aspose file tools*
The moose likes Servlets and the fly likes Maintain Page State and URL parameter after server side validation. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Maintain Page State and URL parameter after server side validation." Watch "Maintain Page State and URL parameter after server side validation." New topic
Author

Maintain Page State and URL parameter after server side validation.

Ali Pirzada
Greenhorn

Joined: Jul 29, 2012
Posts: 3
I am working on demo application for learning purpose. Need some help below. My requirement is to use SERVLET/JSP for this. Values are hard coded just for demo purpose.

Question: Manage Page State after Server Side Validation

Manage Page State?

Form submitted and doPost called on Servlet. In case of error need to post submitted values back to posted to refill form values.

Got 2 options: please look at my servlet doPost

Should I use session
Should I use user object --> I have used this

Am I doing it right or is there any better approach?

Question 2 Important

I arrive at UserEdit.jsp page from UserList.jsp page which uses URL Pattern like /user/edit than my URL in browser is http://localhost:8080/Navigation/user/edit?id=10. I pass id for demo purpose right now.

Problem: In case of form input error when I use
than my URL is changed and becomes http://localhost:8080/Navigation/user/edit.

How can I keep my same URL with id paramter like ?id=10 in URL. I have tried alot but solution found yet. See my Servlet.


User Class



One SERVLET for CRUD operation




2 pages in /WEB-INF/admin

UserList.jsp



UserEdit.jsp

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

Ali Pirzada wrote: Should I use session

Think about this. Why would you use the session? The values just need to go back to the page so that can be placed into the form fields. They do not need to stick around longer than the current request. So what scope would be more appropriate than the session?

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ali Pirzada
Greenhorn

Joined: Jul 29, 2012
Posts: 3
That means my approach is right for sending user object back to page.

Any comments on my second question please?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

I disapprove of going directly to a JSP without a page controller. See this article for details.

And putting Java code inside a JSP has been obsolete and discredited since 2002.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Maintain Page State and URL parameter after server side validation.