File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes State Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "State Exception" Watch "State Exception" New topic
Author

State Exception

Erick Heberling
Greenhorn

Joined: Sep 01, 2005
Posts: 13
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.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Erick Heberling
Greenhorn

Joined: Sep 01, 2005
Posts: 13
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Sep 01, 2005
Posts: 13
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Sep 01, 2005
Posts: 13
jsp code:
=======================================


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


Bean code
====================================================
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Sep 01, 2005
Posts: 13
Thanks a lot for your help.
Erick Heberling
Greenhorn

Joined: Sep 01, 2005
Posts: 13
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: State Exception