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

Page history

Anthony Andras
Ranch Hand

Joined: Nov 09, 2008
Posts: 31
Hi there everyone,

I had a quick question in regards to getting ahold of page history with servlets. Here is my problem:

I am currently in a JSP/Servlet class. For this assignment, I cannot use any MVC framework as I believe the spirit of this assignment is to learn how these frameworks work under the hood.

I am attempting to perform basic form validation on an HTML form when a user issues a request to a servlet using POST. I have a few files defined:

index.jsp (Main JSP)
AmtrackServlet.java (Servlet to process POST requests)
AmtrackForm.java (Form object that maintains state of form as well as performs form validation)
Validateable.java (Interface for future forms that defines a validate method)

Now when a request comes through, my servlet builds the AmtrackForm object based on parameters received from my HTTPServletRequest object. The servlet then calls my validate method. After the servlet calls my validate method, if errors occur, the servlet should forward the request back to the JSP page and my JSP page display the error messages (which will be written into the request).

The issue I am having is when I attempt to process the servlet, I haven't been able to locate a way to grab the URL of the JSP that initially submitted the form. A call to HttpServletRequest.getRequestURL() returns me the url-pattern that I have assigned to the servlet in the servlet mapping (web.xml). I would rather not hard code my forward into RequestDispatcher.forward if I don't have to.

I have basically come up with one solution which seems to be a hack. I started putting a hidden element in my HTML form and passing that through the request.

I was wondering if anyone had any ideas for solutions to this problem or if I am missing something entirely in the servlet API that would give me the solution?

Thank you everyone in advance and sorry it took me so long to describe the issue.

Best,

Anthony
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

What's hack-y about the hidden variable solution? It's a fine way to achieve loose coupling between the servlet and the JSP.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Anthony Andras
Ranch Hand

Joined: Nov 09, 2008
Posts: 31
What I don't like about the hidden value solution is that in the event that the page needs to be moved to a different server, you then have to update all of your hidden fields to refer to the url on the new server or domain.

Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3825

Anthony Andras wrote:What I don't like about the hidden value solution is that in the event that the page needs to be moved to a different server, you then have to update all of your hidden fields to refer to the url on the new server or domain.

Aren't your hidden URL's context relative?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

Anthony Andras wrote:What I don't like about the hidden value solution is that in the event that the page needs to be moved to a different server, you then have to update all of your hidden fields to refer to the url on the new server or domain.

What are the chances that the page will be moved to a different application and server?
Anthony Andras
Ranch Hand

Joined: Nov 09, 2008
Posts: 31
Bear Bibeault wrote:
Anthony Andras wrote:What I don't like about the hidden value solution is that in the event that the page needs to be moved to a different server, you then have to update all of your hidden fields to refer to the url on the new server or domain.

What are the chances that the page will be moved to a different application and server?


Good point.

Thanks!
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11424
    
  85

Anthony Andras wrote:What I don't like about the hidden value solution is that in the event that the page needs to be moved to a different server, you then have to update all of your hidden fields to refer to the url on the new server or domain.

If that was an issue for you, you could probably have the hidden field populated dynamically - there could be easy ways to do this from both server side and client side code.


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Page history