Hi all,
I am new to
struts framework,i write a
test example in struts but i don't know why the execute methode is not executed.
login.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<%@page language="java" %>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<body>
<html:form name="LoginForm" action="/login" type="LoginForm">
<table width="100" border="1" >
<tr><td>Name:</td><td><html:text property="name" /></td></tr>
<tr><td>password:</td><td><html:password property="passWord" /></td></tr>
</table>
<html:submit/>
</html:form>
</body>
</html>
web.xml
<?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>StrutsHello</display-name>
<
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-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.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-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/app.tld</taglib-uri>
<taglib-location>/WEB-INF/app.tld</taglib-location>
</taglib>
</jsp-config>
<welcome-file-list>
<welcome-file></welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
<struts-config>
<!-- ========== Form Bean Definitions ============ -->
<form-beans>
<form-bean name="LoginForm" type="LoginForm" />
</form-beans>
<!-- ========== Global Forward Definitions ========= -->
<global-forwards>
</global-forwards>
<!-- ========== Action Mapping Definitions ======== -->
<action-mappings>
<action path="/login"
type="LoginAction"
name="LoginForm"
input="login.jsp"
validate="true">
<forward name="success" path="hello.html"/>
<forward name="failure" path="login.jsp"/>
</action>
</action-mappings>
</struts-config>
LoginAction class
import javax.servlet.http.*;
import org.apache.struts.action.*;
public class LoginAction extends Action {
public ActionForward executed(ActionMapping mapping,ActionForm form,HttpServletRequest req,HttpServletResponse res)
{
String target=null;
LoginForm lf;
if(form !=null)
{
System.out.println("form");
lf =(LoginForm) form;
if(lf.name==null)
{
System.out.println("failure");
target="failure";
}
else
{
target="success";
System.out.println("sucess");
}
}
else{ System.out.println("nullform"); }
return (mapping.findForward(target));
}
}
LoginForm class
import javax.servlet.http.*;
import org.apache.struts.action.*;
public class LoginForm extends ActionForm {
/**
*
*/
String name=null;
String passWord=null;
public ActionErrors validate(ActionMapping mapping,HttpServletRequest request)
{
ActionErrors errors=new ActionErrors();
System.out.println(errors);
if(name==null)
{
System.out.println("validate");
ActionError newerror=new ActionError("global.error.login.requiredField","name");
errors.add(ActionErrors.GLOBAL_ERROR,newerror);
}
System.out.println(errors);
return errors;
}
public String getName() {
System.out.println("getter");
return name;
}
public void setname(String Name) {
System.out.println(Name);
this.name = Name;
}
public String getpassWord() {
return passWord;
}
public void setpassWord(String Password) {
this.passWord = Password;
}
public void reset(ActionMapping map,HttpServletRequest req)
{System.out.println("reset");
this.name=null;
this.passWord=null;
}
while i am request and submit
Validate method is execute but executre method is not executed here the consol data
May 23, 2009 3:06:06 PM org.apache.struts.util.PropertyMessageResources <init>
INFO: Initializing, config='org.apache.struts.util.LocalStrings', returnNull=true
May 23, 2009 3:06:06 PM org.apache.struts.util.PropertyMessageResources <init>
INFO: Initializing, config='org.apache.struts.action.ActionResources', returnNull=true
May 23, 2009 3:06:07 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-80
May 23, 2009 3:06:07 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
May 23, 2009 3:06:07 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/47 config=null
May 23, 2009 3:06:07 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1292 ms
reset
fh
org.apache.struts.action.ActionErrors@5973ea
org.apache.struts.action.ActionErrors@5973ea
Please help me ..............