[ July 27, 2003: Message edited by: Gregg Bolinger ]
If we use MVC, the JSP always grabs whatever object is available and populates with data from it.
Nothing too earth shattering.
(I never been a fan of beans, no pun intended)
U both are creating a mountain out of a mole hill.
Greg from what i can understand is that u need to resubmit the form onto the same page, am i right ??
Okie, assume we have a page A.jsp ( Our page which needs to come back to itself on submit ) and we have the servlet B, which gets called when A.jsp is submitted.
I simply put a hidden form field on A.jsp, say bringback. The first time i come on A.jsp i have bringback as null. When i submit A.jsp, it checks whether the data submitted has relative data in database. If it does get data from the database, in the servlet i write request.setAttribute("bringback","1"); and use a RequestDispatcher and push back the request to A.jsp.
On A.jsp, check request.getAttribute("bringback") == null. If it is not null means we have come on this page for the second time, load the data.
Am i sounding clear or have i confused u even more??
Your hidden field doesn't accomplish anything that can't be accomplished using the GET/POST, with the added advantage that perdorming functionality based on GET/POST conforms to what GET and POST are supposed to get used for. ie GET to get data, POST to send data.
Now u r confusing me , as far as i know, doget and dopost perform the same action except they support different sizes of data.
Whats the purpose of using a hidden field is, The first time i come on A.jsp, we have not gone to servlet B as yet. At this point of time, how am i to know that the page is getting called for the first time ??
So,the first time the page shows up, the field will have a null value, however the second time the page shows up ( After request passes thru servlet B ) we know that we have to be in edit mode rather than be in new page mode.
I usually prefer to do this in a controller servlet as well, but...I often do exactly what you are talking about for test pages, utility pages, and even some basic admin pages.
The easiest way I have found is to simply add a name attribute to your submit button. Then you need a scriptlet to check for that name in the parameters. It will only exist if the form was submitted by pressing that button, otherwise the parameter will be null. No extra hidden fields either. That's always worked for me.
When the page is requested, simply check for a paramter like..
if (request.getParameter("bla") != null)
do some stuff to fill the rest of the form
so the first time tha page goes it is just
But the next time the page is requested from itself it is
That would work wouldn't it?
I guess you could do that and just call a Servlet from the JSP page being called? I might try that and see how that works.
Originally posted by Deepak Acharya:
Now u r confusing me, as far as i know, doget and dopost perform the same action except they support different sizes of data.
Partly true, there are bigger differences to do with security and (sometimes more importantly) resposibility, but we're heading away from the original discussion. You can still use "POST".equals( response.getMethod() ) in place of an input field that doesn't do anything else.
Originally posted by Jay Dellinger:
The easiest way I have found is to simply add a name attribute to your submit button.
In a purely JSP solution, I usually do either this or use getMethod as above, but in practice we never deploy a JSP without a Servlet anymore, even if the Servlet doesn't do anything real.