• 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

State Exception

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Getting the following error in JDeveloper when using a java bean and forwarding data from a servlet to jsp:

500 Internal Server Error
java.lang.IllegalStateException: bean "NameBean" not found in "session" scopeat _ShowName. _jspService (ShowName.jsp:6)
[/ShowName.jsp]

Not quite sure if this is a bug or whether I am doing something wrong as far as configuring the project.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you bind an instance of NameBean to session before forwarding?
Also, is your bean in a package?

You might want to post the relevant parts of your code.
 
Erick Heberling
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The jsp portion:
<jsp:useBean id="nameBean" type="mypackage.NameBean" scope="session" />

Servlet doGet():
HttpSession session = request.getSession();
NameBean nameBean = (NameBean)session.getAttribute("nameBean");
if (nameBean == null)
{
nameBean = new NameBean();
session.setAttribute("nameBean", nameBean);
}
String firstName = request.getParameter("firstName");
if ((firstName != null) && (!firstName.trim().equals("")))
{
nameBean.setFirstName(firstName);
}
String lastName = request.getParameter("lastName");
if ((lastName != null) && (!lastName.trim().equals("")))
{
nameBean.setLastName(lastName);
}
String address = "/Practice-Project-context-root/ShowName.jsp";
RequestDispatcher dispatcher = request.getRequestDispatcher(address);
dispatcher.forward(request, response);
}
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

type="mypackage.NameBean"



Are you hitting the page before hitting the servlet?
The useBean tag will conditionally create the bean for you if you use the class attribute instead of the type attribute.

At a glance, your servlet code looks right.

Also, are you definately calling the doGet and not the doPost method?
 
Erick Heberling
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it is calling the doGet() and does hit the page before servlet. When I changed the "type" to "class" I got the error for the "scope" in JSP page:
Method <init> not found in mypackage.NumberBean.

Thanks for your help, and sorry for the trouble on this one. Hopefully I can get to root of the problem.
Erick
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post the code to the NameBean?
(Use the UBB Code tags to preserve your indenting so we can easily read it.)
 
Erick Heberling
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
jsp code:
=======================================


servlet code
=========================================


Bean code
====================================================
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here we go:


You're setting the attribute with name: "nameBean" but creating the id with "NameBean".

Change to


Then change all the references on your jsp to match the case in the useBean's id attribute.
 
Erick Heberling
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for your help.
 
Erick Heberling
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ben thanks for your input on this one.

Actually as it turns out there was one more error; JDeveloper did not seem to like the fact that I was not closing the <jsp:useBean> tags. In Tomcat this has never seemed to be a problem.

Thanks again!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic