Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Request Progression  RSS feed

 
Sam Gardner
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Guys,

I have a bit of a vexing problem.

I have four JSP pages that I need to hold all of the same request parameters, but I can't figure out how to do it so that the third page holds the right data.

The first page is a form.

The second page roughly processes the data in the form (makes sure dates are valid, entries requiring integer inputs are actually integers, etc) and passes the data onto a bean which creates a temporary database file, named via the first request parameter.

The third page displays the data entered into the form, and asks the user to verify that it is what he or she wants to submit.

The fourth page is supposed to call a method from the same bean that page 2 used, and move the data from the temp file into the actual database file, and delete the temp file.

Everything works fine until I attempt to submit the verified data. The fourth page is not getting any of the request parameters (request.getParameter(<name_of_parameter>) returns null).

This is messing up my code because the name of the temp file was dynamically created based on the first request parameter, and the bean method which moves the temp data uses the name of the temp file as a parameter.

If anyone can point me to a good tutorial on using persistent request data through multiple JSP pages, or just explain to me how to do it, I'd really appreciate it.

Thanks,

Sam Gardner
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly it sounds like some of your pages aren't pages at all. Does page 2, for example display anything? or does it just do processing? If so, it shouldn't be a JSP at all but a servlet.

To propagate request parameters from page to page you can either store them in the session, where you can retrieve them on any subsequent page, or propagate them by creating hidden inputs in a page's form that will be submitted along with any visible elements.
 
Sam Gardner
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, page 2 only displays if the data isn't entered correctly, its basically just a standin for when I get an actual error reporting method up and running. I just needed something that would check to make sure that everything is in the correct format so that MySQL can read the query that it's sent.

How would I go about saving everything in the session? That's what I've been trying to do but I can't seem to find a decent guide to it online.

Thanks,

Sam Gardner
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sam Gardner:

How would I go about saving everything in the session? That's what I've been trying to do but I can't seem to find a decent guide to it online.


Hmm. That's surprising.
Scoped variables (session included) have been a part of almost every tutorial and book I've ever seen on JSP.

See:
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpSession.html#setAttribute(java.lang.String,%20java.lang.Object)


There is an implicit JSP variable named 'session' that points to your user's session so binding an object to session is as easy as calling:
session.setAttribute("NAME", VALUE);
 
Sam Gardner
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I see.

I got caught up looking at request parameters and forgot that sessions were a JSP item and not an HTML-specific item.

Thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sam Gardner:
forgot that sessions were a JSP item and not an HTML-specific item.

Be aware that sessions have nothing to do with HTML.
[ November 06, 2007: Message edited by: Bear Bibeault ]
 
Sam Gardner
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:

Interesting seeing that sessions have nothig to do with HTML.


Heh, I think I've commented on my lack of experience with anything web-related. I apologize for sounding like an idiot.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sam Gardner:
I apologize for sounding like an idiot.
Not necessary. Everyone's an idiot before they become an expert.

How does the saying go? Something like: "Being an idiot is the first step to becoming an expert"... or some such.
[ November 06, 2007: Message edited by: Bear Bibeault ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!