wood burning stoves*
The moose likes Servlets and the fly likes Beans in Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Beans in Servlet" Watch "Beans in Servlet" New topic
Author

Beans in Servlet

Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
Hi,
I'm having trouble initializing a bean in a servlet and then using it in another jsp page that I forward to with the Request Dispatcher. Can some one tell me what's wrong with this? The following is the relevant Servlet code:
public void init() throws ServletException{
testerBean testBean= new testerBean();
testBean.setMessage("THIS SHOULD WORK");
getServletContext().setAttribute("testBean", testBean);
The bean is in a package called core.
Here's the JSP tag I'm using:
<jsp:useBean id="testBean" class="core.testerBean"
scope="application" />
<jsp:getProperty name="testBean"
property="message" />
I'm trying to initialize the bean in the servlet, including the message attribute of the bean, and then fowarding to the jsp page so the jsp page can use the bean. I'm getting the default message I set up in the bean class. Any help would be great. I've already looked at the Core JSP book, and the Oreilly JSP book, but I think I'm missing something.
thanks, Sean.
Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
Well, as usually is the case, I'm an idiot. I kept recompiling the servlet without restarting the server, so the changes weren't being demonstrated in the jsp page. Everything works fine now.

[This message has been edited by Sean Casey (edited September 09, 2001).]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Beans in Servlet
 
Similar Threads
Extracting data from a bean
servlet , bean , jsp Communication
Error using c:set for javaBean property
JSF navigation questions
can not load beanclass