Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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: 67637
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: 67637
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
 
I have a knack for fixing things like this ... um ... sorry ... here is a consilitory tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic