aspose file tools*
The moose likes Servlets and the fly likes RequestDispatcher - regarding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "RequestDispatcher - regarding" Watch "RequestDispatcher - regarding" New topic
Author

RequestDispatcher - regarding

Vanchi Nathan
Ranch Hand

Joined: Feb 24, 2004
Posts: 107
Hello,
Is it ok to pass some data from a servlet to an html page using RequestDispatcher.include method?
Please reply...


Best regards,<br /> <br />vanchin
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
What is the advantage of doing that? HTML is static it can't do anything with that data.
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
What is the advantage of doing that? HTML is static it can't do anything with that data.
Vanchi Nathan
Ranch Hand

Joined: Feb 24, 2004
Posts: 107
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

Joined: Mar 18, 2004
Posts: 572
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

Joined: Feb 24, 2004
Posts: 107
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

Joined: Feb 24, 2004
Posts: 107
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

Joined: Mar 18, 2004
Posts: 572
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

Joined: Aug 29, 2003
Posts: 155
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.


SCJP, SCWCD, SCBCD, IBM CSD WebSphere v5, <br />A+, MCP 2000 and 2000 server, CST, and few incompleted certification tracks.<br /> <br />Ivory Coast<br /> <br />Analyze your web Request/Response @ <a href="http://webtools.servehttp.com" target="_blank" rel="nofollow">http://webtools.servehttp.com</a> down for a while...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: RequestDispatcher - regarding