• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher - regarding

 
Vanchi Nathan
Ranch Hand
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • 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...
 
Ali Gohar
Ranch Hand
Posts: 572
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Brahim Bakayoko
Ranch Hand
Posts: 155
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic