Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

two questions

 
sachin dabhade
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dear all,
i have two questions,
if anyone can help me,plz help me
1.what is difference between doGet and doPost methods.
also which shd be used when.
what is difference between method=POST
and method=GET of html page?

2.how can i redirect a page to other after a delay of few seconds?
plz reply
thanks in advance
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It all depends on what you are doing with your servlets. To send form information, you want to use doPost. If you just want to retrieve information from the server, you use doGet. You may want to check out the Servlet tutorial at Sun's site, for some more information.
Bosun
 
sachin dabhade
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but i have tried with the code in which i can
fetch or receive the information from the server using
doPost method.It finely works.
i send the parameter from html to servlet(say name) and then the code executes the database query (select * from tab where name=xyz )
and send the result back to the client.
i have used doPost
 
Art Metzer
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right, Sachin. GET and POST can apparently be used interchangeably. Like Bosun said, though, you should use doGet() to retrieve information from the server, and doPost() to post form data to the server, if for no other reason, to make your intent clear to other servlet programmers.
According to Jason Hunter, author of Java Servlet Programming (an excellent book on the topic of servlets, by the way),
"In practice, the use of GET and POST has strayed from the original intent....Just remember that GET requests, because they can be bookmarked so easily, should not be allowed to cause damage for which the client could be held responsible. In other words, GET requests should not be used to place an order, update a database, or take an explicit client action in any way." (p. 17)
I'll end with this, Sachin: Just because you CAN do something doesn't mean you SHOULD.
Art
 
sachin dabhade
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you both of you sir.
the picture is much clear for get and post methods.
do you have any idea for my second query??
about redirecting the page??
 
khudiram Barik
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now since you understand the first(doGet/doPost), method = "Get" and method = "Post" are similar but they appear in the html form. When your action="nextPage.jsp" or a "servletname" then the nextPage servlet's corresponding method is called depending upon method= "Get"/"Post" you have specified.
method Get coresponds to Servlet's doGet
method Post coresponds to Servlet's doPost.
Hope this helps.

 
khudiram Barik
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do it so many ways. One way to use meta tag of html.
<meta http-equiv="refresh" content="5;url=http://www.javaranch.com/index.html">
Thanks.
 
sushant prabhu
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry if i am adding to the confusion of get and post.
when we use get i hav read that the whatever are ur form values go along with the url (query string) to the server.
Whereas i hav read that in post the form data actually travels
as part of the http packet body so we cannot see it appended to the URL as in get.
as in the case of get isnt the request to the server(along with which the query string is attached a part of the http packet)
 
sachin dabhade
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sushant prabhu:
sorry if i am adding to the confusion of get and post.
when we use get i hav read that the whatever are ur form values go along with the url (query string) to the server.
Whereas i hav read that in post the form data actually travels
as part of the http packet body so we cannot see it appended to the URL as in get.
as in the case of get isnt the request to the server(along with which the query string is attached a part of the http packet)


so can this be called that the Post method is more secure that the get method??
as it hides the information and disables it from appearing it into browsers address bar while sending it?
 
sachin dabhade
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got the answer for my first query, can any body tell me about page redirecting??
My second query was :
how can i redirect a page to other after a delay of few seconds?
sachin
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a http header named 'HTTP-EQUIV=REFRESH' like following to give delay and redirect to another page.

Please refer to this thread. http://www.javaranch.com/ubb/Forum7/HTML/002604.html
regds
maha anna

[This message has been edited by maha anna (edited March 25, 2001).]
 
Amit Ranjan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For redirecting the user to another page u can use
location.replace method of javascript
location.replace(URL)
example
write the following code in index.html
function a()
{
location.replace("www.bharatnet.com)
}
Thanx
Amit Ranjan
 
Amit Ranjan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I missed double quotes
The correct one is
location.replace("www.bharatnet.com");
 
Raveendran Karunakaran
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dear Sachin,
by default if you write both these methods DOGET AND DOPOST the first time you call the page the doget is called.
the other difference is that doGet is not intent posting data from the user and has limitations.
while doPost is intent only for storing data in the database.
 
DC Dalton
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In reference to sushant's post about doGet() vs do Post() yes the Get method appends the information in the url IE: "http://www.somewhere.com/servlet/someServlet?pageName=somePage". The servlet (someServlet) is followed by a ?. Anything after that ? is the information to be passed to the servlet, or whatever. In the above example the servlet is expecting a parameter called pageName. If you look in your location bar on the post message page of this program you will see a very similar string that is sending information to the posting.cgi script on this server. This way of doing things is widely used, although probably not correct (see Art's post above) The main downfall of this way of doing things is in fact security as any information is visible within the url string. You NEVER use a get with sensitive information! Using a POST allows you to encript the information & send it in a packet. Hope this clears up your confusion.
[This message has been edited by DC Dalton (edited June 25, 2001).]
 
Ganesh Anekar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Sachin,
The basic difference between GET and POST is as follows:
In Get method - all the parameters are passed through qureystring to The mentioned action...IT passes only FORM input parameters not whole form..
In Post method - all the parameters are passed to mentioned action i.e. The input parameters along with names...u can write a simple program and check...
So when u want hide the parameters the Use GET method...as there is limitation on this, u can not pass more than 1000 charactors.. In that case Use POST method...
Ganesh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic