Results 1 to 5 of 5
Thread: Error in Struts Application
- 06-20-2010, 06:03 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 3
- Rep Power
- 0
Error in Struts Application
Hi friends,
I am getting an error like the follow while trying to run an dynamic web project from Eclipse and JBoss application server ONLY THERE IS NO INTERNET CONNECTION in MY machine and the application working fine with internet connection.
ERROR:
javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection
LoginAction.java
Java Code:/** * */ package test.action; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import test.forms.LoginForm; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; public class LoginAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String target = null; LoginForm loginForm = (LoginForm)form; if(loginForm.getUserName().equals("admin") && loginForm.getPassword().equals("admin123")) { target = "success"; request.setAttribute("message", loginForm.getPassword()); } else { target = "failure"; } return mapping.findForward(target); } }
LoginForm.java
Java Code:/** * */ package test.forms; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; public class LoginForm extends ActionForm { private String userName = ""; private String password = ""; public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors actionErrors = new ActionErrors(); if(userName == null || userName.trim().equals("")) { actionErrors.add("userName", new ActionMessage("error.username")); } try { if(password == null || password.trim().equals("")) { actionErrors.add("password", new ActionMessage("error.password")); } }catch(Exception e) { e.printStackTrace(); } return actionErrors ; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
MessageResource.properties
label.username = Login Detail
label.password = Password
label.welcome = Welcome
error.username =Username is not entered.
struts-config.xml
Java Code:<?xml version="1.0" encoding="ISO-8859-1" ?> <!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="loginForm" type="test.forms.LoginForm" /> </form-beans> <global-exceptions> </global-exceptions> <global-forwards></global-forwards> <action-mappings> <action path="/loginAction" name="loginForm" validate="true" input="/index.jsp" type="test.action.LoginAction"> <forward name="success" path="/welcome.jsp" /> <forward name="failure" path="/index.jsp" /> </action> </action-mappings> <!-- Message Resources --> <message-resources parameter="resource.MessageResource"></message-resources> </struts-config>
web.xml
Java Code:<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>MyStrutsApps</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <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.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <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> </jsp-config> </web-app>
index.jsp
Moderator Edit: Code tags addedJava Code:<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Login page | Hello World Struts application in Eclipse</title> </head> <body> <h1>Login</h1> <html:form action="/loginAction" name="loginForm" type="test.forms.LoginForm"> User ID <html:text name="loginForm" property="userName"></html:text> <br/> Password <html:password name="loginForm" property="password"></html:password> <html:submit/> <html:reset/> </html:form> </body> </html>
Last edited by Fubarable; 06-20-2010 at 06:06 PM. Reason: Moderator Edit: Code tags added
- 06-20-2010, 06:06 PM #2
Member
- Join Date
- Jun 2010
- Posts
- 3
- Rep Power
- 0
Is it required to have an Internet connection while running the application?????
-
Hello, and welcome to the forum. I hope you don't mind that I edited your code and added code tags which should help make your posted code retain its formatting and be more readable.
To do this yourself, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.
Another way to do this is to manually place the tags into your code by placing the tag [code] above your pasted code and the tag [/code] below your pasted code like so:
Best of luck, and again, welcome!Java Code:[code] // your code goes here // notice how the top and bottom tags are different [/code]
- 06-20-2010, 06:10 PM #4
Member
- Join Date
- Jun 2010
- Posts
- 3
- Rep Power
- 0
thanks for ur guidance.:)
- 06-21-2010, 10:50 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
You don't need an internet connection if you are just running this locally (ie localhost).
Are there any parse errors with respect to the struts-config? This usually goes hand in hand...that is, there's an error in the config, which means it can't read the mappings, so you also get the mappings error.
Similar Threads
-
pinting Application in Struts
By kishan in forum Advanced JavaReplies: 2Last Post: 02-18-2010, 09:17 AM -
Struts application on Intranet
By sprateek in forum Web FrameworksReplies: 3Last Post: 01-22-2010, 08:25 AM -
Exception in Struts Application
By shuklajayb in forum Web FrameworksReplies: 1Last Post: 02-20-2009, 07:21 AM -
URL Problem with IE7 in my struts Application
By SreenivasGurramkonda in forum Web FrameworksReplies: 0Last Post: 11-27-2008, 08:14 AM -
Struts 2.x sample application .......?
By prabhurangan in forum Web FrameworksReplies: 7Last Post: 06-26-2008, 10:50 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks