• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Need the JSP equivalent

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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. ?
 
Sheriff
Posts: 67756
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
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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67756
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
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?
 
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic