• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need the JSP equivalent  RSS feed

 
Tontang Bei
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JSp where I want to add an object to the session and then forward it to a java class. With servlets we have this kind of code

HttpSession session=request.getSession()
session.setAttribute("user",user);

RequestDispatcher dispatcher=getServletContext().getRequestDispatcher("/url");
dispatcher.forward(request,response);

How do I do this in JSP. ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66153
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you want to do this?

JSPs are view components. Why move this controller code from a servlet, where it belongs, to a JSP, where it does not?
[ May 14, 2007: Message edited by: Bear Bibeault ]
 
Tontang Bei
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, but how do you send an object to a Java class from a JSP? is that not recommened?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66153
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The bigger question is why are you forwarding from a JSP? A JSP is usually the "end point" of a request that formats the response sent to the browser.

In a web app following modern patterns, it's a rare thing to forward from a JSP -- in fact, I cannot recall the last time I did such a thing.

You mentioned servlets, so I assumed that you were following a Model 2 pattern. Is this not so?
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Bear mentioned why are you using a JSP to do this?
Anyways this can be done in a JSP as follows(but never do this,it is supposed to be a view component)

Regards,
Srikkanth
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!