• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

regrd refresh in browser

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a dbt how refresh works for servlets.
I have a html page which asks user for color.When submitted control goes to below servlet which dispalys users color..Thts ok.

http://localhost:9000/chapter01/DemoServlet2uri
Ur color:entered color

My dbt is, when i refereshed this url or clicked enter with same address on this browser's window addr bar, is a new request sent to the server ? or is the same old request ? bcas i think if a new request is sent then it shuld dispaly the color=null bcas this req doesnt have any user entered color val.
If its the same old req then wht is the mechanism behind it?
can anyone clear me this dbt or give me any link to study.

Thnx
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a brand new request. The color is not null because the servlet is probably somehow storing the color. Post your code, so we can take a look at it.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Mysha,
Just complementing Leandro's explanation. We should remember that HTTP is a stateless protocol. So, every request is seen as a brand new request by the web server. It's not possible to make the question "is it the same old request". Regarding only HTTP mechanisms each request is a new request even if it comes from the same client, to the same server and to the same resource (JSP, servlet, HTML, ...).
Regards,
Alexandre.
 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interestingly, if you have sessions maintained and set the color as a session attribute, you would be good.
 
mysha ahamed
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,
I thought it will be clear if i posted the code.I have an html which asks color frm user.next servlet which forwards the same req to 2nd servlet.

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you use requestdispatcher's forward method, you use the same requext object. That's why you get such results. Request dispatcher forward the request you send from client to another servlet or jsp, but client doesnt know this.
If you want, to create new request, you must use request.sendRedirect() method
 
mysha ahamed
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey
I didnt get u.Second time since a new request object(whic has no color) is sent to the servlet n this req obj is forwarded..So the color value shuld be null?
Thnx
 
Alexandre Cervieri
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you submit the form the first time the following will be execute:
DemoServlet1.doPost --> DemoServlet2.doPost --> back to client

When you press enter in the brower's address field what address is displayed there? http://localhost:9000/chapter01/DemoServlet1uri or
http://localhost:9000/chapter01/DemoServlet2uri?

If it is http://localhost:9000/chapter01/DemoServlet2uri, than the DemoServlet2 is executed and is obtaining the correct color from the session, that I think is based on cookies in your case.

However, if the address field is displaying http://localhost:9000/chapter01/DemoServlet1uri, I don't know exactly what is happening. Method doGet should be called, but you didn't overriden it, so
 
Alexandre Cervieri
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just complementing my previous post.
Instead of pressing Enter in the browser's address field, if you press F5 (reload/refresh) in the page that is displaying your color (not the form), then what will happen is the same flow that ocurred in the first time:
form submit (browser "saved" the values you entered) --> DemoServlet1.doPost --> DemoServlet2.doPost --> back to client
right?
 
mysha ahamed
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Thnx for ur reply.The url tht i refreshed or pressed enter is the below one.This url is for the first servlet which comes after submitting form..

http://localhost:9000/chapter01/DemoServlet1uri

When i refresh ,the same color is getting displayed.I have put some debug
system.out.println(),which r displayed in tomcat console..when i refresh,
the debug stmt from DemoServlet1 & DemoServlet2 r dispalyed.So,
when refreshed DemoServlet1.doPost()->DemoServlet2.doPost(). r invoked in this order.
I dont know why the doPost() is invoked n why the same color is dispalyed..

Thnx
reply
    Bookmark Topic Watch Topic
  • New Topic