aspose file tools*
The moose likes Struts and the fly likes Trying to execute my First struts app but receiving 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 » Frameworks » Struts
Bookmark "Trying to execute my First struts app but receiving "ServletException" " Watch "Trying to execute my First struts app but receiving "ServletException" " New topic
Author

Trying to execute my First struts app but receiving "ServletException"

Vijay Bharghav bheemineni
Greenhorn

Joined: Aug 31, 2005
Posts: 29
Hi All,

I am trying to execute following struts application but I am receiving following error, could any one please help me.I searched the posts, I tried all the solutions but my application is still not working.

============================Error==========================================
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Cannot find ActionMappings or ActionFormBeans collection
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.VASIndex_jsp._jspService(VASIndex_jsp.java:98)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection
org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:798)
org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:506)
org.apache.jsp.VASIndex_jsp._jspx_meth_html_form_0(VASIndex_jsp.java:116)
org.apache.jsp.VASIndex_jsp._jspService(VASIndex_jsp.java:88)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


===========================================================================

Following is my directory structure

C:\VASVijay\Tomcat 5.0\webapps\VASEcl03
|-VASIndex.jsp
|-VASResult.jsp
|-WEB-INF
|
|-classes
| |
| |-ch03
| |-LookUpAction
| |-LookUpForm
|-lib
| |-All my jar files are placed here
|-web.xml
|-struts-config.xml

=============================web.xml=======================================
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>

<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>

<servlet>
<servlet-name>FrontController</servlet-name>
<servlet-class>org.apache.struts.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>FrontController</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>VASIndex.jsp</welcome-file>
</welcome-file-list>

<taglib>
<taglib-uri>/WEB-INF/myTld/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/myTld/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/myTld/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/myTld/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/myTld/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/myTld/struts-html.tld</taglib-location>
</taglib>

</web-app>

===========================================================================
============================struts-config.xml==============================
<?xml version="1.0" encoding="ISO-8859-1" ?>

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

<struts-config>

<form-beans>
<form-bean name="LookUpForm" type="ch03.LookUpForm" />
</form-beans>

<action-mappings>
<action path="/LookUp"
type="ch03.LookUpAction"
name="LookUpForm"
scope="session"
validate="true">
<forward name="success" path="/VASResult.jsp" />
<forward name="failure" path="/VASIndex.jsp" />
</action>
</action-mappings>
</struts-config>

===========================================================================

Source code for the classes "LookUpAction" and "LookUpForm"

==============================LookUpAction.java============================
package ch03;

import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.Action;


public class LookUpAction extends Action
{

private String target="success";
private Double quote=null;

protected Double getQuote(String symbol)
{
if(symbol.equalsIgnoreCase("SUNW"))
{
return new Double(99.00);
}
return null;
}

public ActionForward excute(ActionMapping mapping,ActionForm form,HttpServletRequest req,HttpServletResponse res)
{
ch03.LookUpForm lookupform=(ch03.LookUpForm)form;
String symbol=lookupform.getSymbol();
quote=this.getQuote(symbol);

if(quote==null)
{
target="failure";
}
else
{
req.setAttribute("PRICE",quote);
}

return mapping.findForward(target);
}
}


===========================================================================
==============================LookUpForm.java============================
package ch03;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class LookUpForm extends ActionForm
{
private String symbol=null;
public void setSymbol(String symbol)
{
this.symbol=symbol;
}
public String getSymbol()
{
return symbol;
}
public void reset(ActionMapping mapping,HttpServletRequest request)
{
this.symbol=null;
}

}
===========================================================================

Vijay Bharghav bheemineni
Greenhorn

Joined: Aug 31, 2005
Posts: 29
Sorry I forgot to give the code for "VASIndex.jsp" or "VASResult.jsp"

=================================VASIndex.jsp==============================
<html>
<%@ page language="java" %>
<%@ taglib prefix="html" uri="/WEB-INF/myTld/struts-html.tld" %>

<head>
<title> VAS First Struts Application </title>
</head>

<body>
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td><h1>VAS</h1></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
</table>

<html:form action="VASEcl03/LookUp" type="cho3.LookUpForm" name="LookUpForm" >
<table width="45%" border="0" >
<tr>
<td>Symbol:</td>
<td><html:text property="symbol" /></td>
</tr>
<tr>
<td colspan="2" align="center"><html:submit /></td>
</tr>
</table>
</html:form>
</body>
</html>
===========================================================================

================================VASResult.jsp==============================
<html>
<%@ page language="java" %>
<%@ taglib prefix="html" uri="/WEB-INF/myTld/struts-html.tld" %>

<head>
<title> VAS First Struts Application </title>
</head>

<body>
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td><h1>VAS</h1></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>Current Price: <%= request.getAttribute("PRICE") %></td>
</tr>
<tr>
<td> </td>
</tr>
</table>

</body>
</html>
===========================================================================
Lalit Vora
Ranch Hand

Joined: Jun 22, 2006
Posts: 37
Did you compile Lookupform.java and LookupAction.java and keep .class files in ch03 folder.

try to compile using javac -d . LookupForm.java LookupAction.java

I a running same application. Tutorial of wrox
Vijay Bharghav bheemineni
Greenhorn

Joined: Aug 31, 2005
Posts: 29
Hi Lalit, I had compiled my classes and placed them in "/WEB-INF/classes".
I checked every thing mappings between "<html:form action....>" and the "struts-config.xml" action tag "path".

I had copied all the jar files "/WEB-INF/lib" folder also.

I am still trying different options to see that this app get executed.
Do u have any idea, if this problem is related to "DTD" or struts version related problems?.

Regards,
Vijay Bheemineni.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The error message you are getting indicates that the Struts ActionServlet has not initialized properly.

1. Check your web.xml file and make sure that you have indicated <load-on-startup>1</load-on-startup> in the xml block that defines the action servlet.

2. If you did specify load on startup for the Action Servlet and are still getting this error, it is because the ActionServlet is throwing an exception when trying to initialize. To see the exception that it is throwing, look at the System Out log when the application first starts up. The most common error is malformed XML in your struts-config.xml file. The error message in the log should help you find the line on which the XML error is occurring.


Merrill
Consultant, Sima Solutions
Lalit Vora
Ranch Hand

Joined: Jun 22, 2006
Posts: 37
Hi,

html:form action="VASEcl03/LookUp" type="cho3.LookUpForm" name="LookUpForm

from this line in jsp page only keep html:form action=/Lookup and try to run. If this does not run let me know
Vijay Bharghav bheemineni
Greenhorn

Joined: Aug 31, 2005
Posts: 29
Hi Lalit & Merrill,

Thanks for your help.I was trying that option when I posted this question.
My actual code is

<html:form action="/LookUp" type="ch03.LookUpForm" name="LookUpForm">

I have tried all the options,by trial and error I found out that above tag is creating the problem but I am not able to pin point the error still.

I am thinking to re-build the application from scratch.

I guess next time it would be successfull


[ June 26, 2006: Message edited by: Vijay Bharghav bheemineni ]
[ June 26, 2006: Message edited by: Vijay Bharghav bheemineni ]
Vijay Bharghav bheemineni
Greenhorn

Joined: Aug 31, 2005
Posts: 29
Hi All,

Finally I am able to execute my application. I have re-written the application and it works But I am yet to find the reason for version1 not working.

Thanks lalit and Merrill for your help.

Vijay Bheemineni.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trying to execute my First struts app but receiving "ServletException"