• Post Reply Bookmark Topic Watch Topic
  • New Topic

Keeping old request parameters alive  RSS feed

 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a request is forwarded from A.jsp to B.jsp, and then to C.jsp, the request params from A.jsp are cleared. Now as a workaround, I did this in B.jsp before forwarding it to C.jsp:



But this param duplicating feels.. bad


Is there another, easy way to keep the params?
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why dont you use session attributes.




Hope this helps
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What in the servlet world is called forwarding actually preserves request parameters (it happens all on the server). It sounds more like you are doing a client-side redirect?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jan Sterk:
If a request is forwarded from A.jsp to B.jsp, and then to C.jsp, the request params from A.jsp are cleared.
As Ulf indicated, if you are really forwarding from JSP to JSP (which, by the way, would be a very odd thing to be doing), then the parameters are preserved since it is the same request that will be forwarded along.

We'll need to know how you are really traversing from JSP to JSP to help you out.
 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for your replies. I realize now my post was not complete.

Originally posted by Ulf Dittmer:
What in the servlet world is called forwarding actually preserves request parameters (it happens all on the server). It sounds more like you are doing a client-side redirect?

No, not a redirect.

I'm programming a simple forum app, just as an exercise. There is a 'thread.jsp', which shows all posts. Each post has an edit-button. For the whole thread there's an add-post-button.

I want to use the same jsp (edit.jsp) for both an edit-old-post action and an add-a-new-post action. (The only thing one action differs from the other, is that an edit-old-post action needs a variable that holds the index of the post).

When the user submits the edited text, thread.jsp has to appear again.


Now my current design for both actions is this.

thread.jsp > Front Controller.do > editor.jsp > Front Controller.do > Submit.do > thread.jsp

The .do things are servlets.

So the request params from thread.jsp are passed to Front Controller.do; then Front Controller.do forwards the request to editor.jsp. Now if I understand well, at this point the request stays on the server side, since the jsp is actually a class. The 'jsp-class' creates a html response, with e.g. the index value from the original request copied in the html as a hidden parameter (as shown in my previous post). Then the response is send to the client.

It works, but I'm looking for a more elegant way.


Originally posted by Amit Ghorpade:
Why dont you use session attributes.


It crossed my mind also, and it is probably a solution. But the downside is that you also get code that's just copying parameters.
[ July 05, 2008: Message edited by: Jan Sterk ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now if I understand well, at this point the request stays on the server side, since the jsp is actually a class.

I'm not sure what you mean by this. Requests are a server-side concept, so I'm not sure what is meant by "stays on the server".

At the point that the response is sent to the client, the request is dismissed, and any parameters or scoped variables associated with it go away with it.

If you want data to stay around for longer than a single request/response cycle, you need to do something to persist it. Whether that's the session, a database, or hidden inputs in the response depends on how you want to use the data.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!