• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Maintain Page State and URL parameter after server side validation.

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic