• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to access a class in servlet context from JSP

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I set attribute 'msg' in my servletContext, like this, before I dispatch to a JSP.



And In my JSP, I try to access the 'msg' object like this:



But I get an error like this when I run:




Can you please tell me what did i do wrong?

Thank you.
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the bean is in the context scope, how can you get it from the session scope ?
So the problem lies in the scope.


Hope this helps
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you do not specify a class attribute, this action expects a scoped variable of the specified name and type to already exist.
 
Amit Ghorpade
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by seetharaman venkatasamy:
When you do not specify a class attribute, this action expects a scoped variable of the specified name and type to already exist.



It does exist, isn't it?
 
ying lam
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.

For my case of 'session' scope. Where I should I put my Msg object with the key 'msg' so that JSP can see it when I dispatch to it from the servlet.

Thank you.
 
Sheriff
Posts: 67746
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
Unless you have a good reason for it to stay around for the long haul, you should be placing it in request scope. Putting it in session scope is a good way to keep it around for longer than the current request, but you should only do that when necessary. Using application scope (the servlet context) should only be done for information that needs to be shared across al users.
 
ying lam
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for all the help.

I have this in my code:



And i have a breakpoint in my msg getTitle() method. It does break (calling from tomcat) and the function does return the right value.

But why in my final page (view source in a browser), i only see

 
Bear Bibeault
Sheriff
Posts: 67746
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
You really should learn to use the EL rather than scriptlets and scriptlet expressions, but your syntax:
is a scriptlet statement. In order to emit a value, you need to use a scriptlet expression, whose syntax would be:

However, again, you should look into modernizing your JSP knowledge with the Expression language (EL).
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic