File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Maintain Page State and URL parameter after server side validation.

 
Ali Pirzada
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ali Pirzada
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic