• 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

RequestDispatcher - regarding

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Is it ok to pass some data from a servlet to an html page using RequestDispatcher.include method?
Please reply...
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the advantage of doing that? HTML is static it can't do anything with that data.
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the advantage of doing that? HTML is static it can't do anything with that data.
 
Vanchi Nathan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is to respond the the request posted together with a reply from the server...say for example...a user needs to submit a form ...but if there is anything worng after the server side validation...the server can reply with a message and redirect to the same html form.
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For this purpose better way is to use a controller servlet which will do the server side processing and if there occur anything wrong redirect to the error page otherwise to the success page.
 
Vanchi Nathan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to display in such a way that the client need not reenter the whole form rather enter only the wrong enteries. If i do it on your way.. the client may have to reenter the whole form data...right
 
Vanchi Nathan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ali Gohar,
Thanks, i got the point that for my needs the RequestDispatcher's include method is not the right one...Then how can i respond to the client together with a message and the form (can be empty)?
Pl. guide..
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One way is to use a parameter in query string that identifies that an error has been occured.
Suppose on the next page you process data and found that something is wrong then you redirect to that form page with an addition query string parameter like "error=true" or something like that.
and in form page you get that parameter and if request.getParameter() method returns null it means that show form only not the error message but if it returns the value of that parameter then it means an error has been occured and show the error as well as the form.
May be this would help.
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can always include the logic in the page that hosts the form.
<input name="name" type="text" value='<%=(request.getParameter("XYZ")!= null ? request.getParameter("XYZ") : "")%>'>
- set a condition to display the error to the user where appropriate in the page
- add an error attribute (collection of errors if needed) to the request while in the servlet if errors occur
- have the RequestDispatcher forward to the original page
My prefered method is to create a preview jsp page where I verify the inputs before submiting for processing.
 
What does a metric clock look like? I bet it is nothing like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic