File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Once more: javax.servlet.jsp.JspException: Cannot find bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Once more: javax.servlet.jsp.JspException: Cannot find bean" Watch "Once more: javax.servlet.jsp.JspException: Cannot find bean" New topic
Author

Once more: javax.servlet.jsp.JspException: Cannot find bean

Anatoliy Chernat
Greenhorn

Joined: Jan 03, 2012
Posts: 2
Hi guys,

I saw similar issue posted some time ago, but it did not help me to solve my simple case.
I'm trying to rum struts application on IBM WebSphere Server and getting this Exception:

[1/3/12 11:09:39:624 MST] 00000024 WebApp E [Servlet Error]-[/helloWorld.jsp]: javax.servlet.jsp.JspException: Cannot find bean: "HelloWorldForm" in any scope
at org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:935)
at org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:225)
at com.ibm._jsp._helloWorld._jspx_meth_bean_write_0(_helloWorld.java:101)
at com.ibm._jsp._helloWorld._jspService(_helloWorld.java:75)
at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:85)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:966)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:463)
at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:115)
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:168)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3129)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:238)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:811)
at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1433)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:93)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:465)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:394)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:102)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:152)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:213)
at com.ibm.io.async.AbstractAsyncFuture.fireCompletionActions(AbstractAsyncFuture.java:195)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:194)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:741)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:863)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1510)

My web.xml:
---------------

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config-test.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<jsp-config>
<taglib>
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>

It's referring this struts config file:
---------------------------------------
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">


<struts-config>
<form-beans>
<form-bean name="HelloWorldForm" type="com.schwab.pas.ui.form.HelloWorldForm"/>
</form-beans>

<global-forwards >
<forward name="HelloWorld" path="/helloWorld.jsp"/>
</global-forwards>

<action-mappings>
<action input="/index.jsp" name="HelloWorldForm" path="/HelloWorld" scope="session" type="com.schwab.pas.ui.actions.HelloWorldAction">
<forward name="success" path="/helloWorld.jsp" />
</action>
</action-mappings>

</struts-config>

I'm using 2 jsp files.
index.jsp:
------------------

<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<logic:redirect forward="HelloWorld"/>

helloWorld.jsp:
-----------------------
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello World</title>
</head>
<body>
<h1><bean:write name="HelloWorldForm" property="message"></bean:write></h1>
</body>
</html>

My form bean:
--------------------
package com.schwab.pas.ui.form;

import org.apache.struts.action.ActionForm;

public class HelloWorldForm extends ActionForm {
private static final long serialVersionUID = -473562596852452021L;

private String message;

public String getMessage() {

return message;
}

public void setMessage(String message) {

this.message = message;

}
}

Action class:
-----------------
package com.schwab.pas.ui.actions;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.schwab.pas.ui.form.HelloWorldForm;

public class HelloWorldAction extends Action {

public ActionForward execute(ActionMapping mapping, ActionForm form, ServletRequest arg2, ServletResponse arg3) throws Exception {
// TODO Auto-generated method stub
HelloWorldForm hwForm = (HelloWorldForm) form;
hwForm.setMessage("Hello World");
return mapping.findForward("success");

}

}

I'm invoking the application with this URL:
http://localhost:9080/myApp/index.jsp

Thank you very much for any help
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
>Cannot find bean: "HelloWorldForm" in any scope

easiest way to put a form bean in scope is to construct a form on the page


<html:form action="/HelloWorld">
<h1><bean:write name="HelloWorldForm" property="message"></bean:write></h1>

</html:form>


In your action you should not have to construct a HelloWorldForm yourself.
In general with struts if you are instantiating form/action objects you are doing the wrong thing. The framework is responsible for creating/populating them and providing them for you.
In this case I think you can cast the form parameter received in the action to a HelloWorldForm.

I also think the global forward in your struts config should direct to your action, rather than your jsp page:


So when you visit the url, it should serve the index page, find the struts redirect look up this global forward, and then invoke the action to instantiate the required form bean before forwarding to helloWorld.jsp to display your message.

Also, this question probably belongs in the struts forum.
Redirecting you there now...
Anatoliy Chernat
Greenhorn

Joined: Jan 03, 2012
Posts: 2
Stefan,

With the changes you suggested the error is gone, but the message "Hello World" does not show up. I was expecting to hit a breakpoint in my HelloWorldAction#execute method in the debug mode , but it did not happen.

Thanks a lot for your help
 
 
subject: Once more: javax.servlet.jsp.JspException: Cannot find bean
 
Similar Threads
Parsing error processing resource path /WEB-INF/struts-config.xml
Error page configured in web.xml not working
servlet action is not available
a question about struts....please help
error while creating struts application