Results 1 to 5 of 5
  1. #1
    rajesh.moyra is offline Member
    Join Date
    Jun 2010
    Posts
    3
    Rep Power
    0

    Default 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
    Java 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>
    Moderator Edit: Code tags added
    Last edited by Fubarable; 06-20-2010 at 06:06 PM. Reason: Moderator Edit: Code tags added

  2. #2
    rajesh.moyra is offline Member
    Join Date
    Jun 2010
    Posts
    3
    Rep Power
    0

    Default

    Is it required to have an Internet connection while running the application?????

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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 [cod&#101;] above your pasted code and the tag [/cod&#101;] below your pasted code like so:

    Java Code:
    [cod&#101;]
      // your code goes here
      // notice how the top and bottom tags are different
    [/cod&#101;]
    Best of luck, and again, welcome!

  4. #4
    rajesh.moyra is offline Member
    Join Date
    Jun 2010
    Posts
    3
    Rep Power
    0

    Default

    thanks for ur guidance.:)

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default

    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

  1. pinting Application in Struts
    By kishan in forum Advanced Java
    Replies: 2
    Last Post: 02-18-2010, 09:17 AM
  2. Struts application on Intranet
    By sprateek in forum Web Frameworks
    Replies: 3
    Last Post: 01-22-2010, 08:25 AM
  3. Exception in Struts Application
    By shuklajayb in forum Web Frameworks
    Replies: 1
    Last Post: 02-20-2009, 07:21 AM
  4. URL Problem with IE7 in my struts Application
    By SreenivasGurramkonda in forum Web Frameworks
    Replies: 0
    Last Post: 11-27-2008, 08:14 AM
  5. Struts 2.x sample application .......?
    By prabhurangan in forum Web Frameworks
    Replies: 7
    Last Post: 06-26-2008, 10:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •