标签:
1、概述
2、resultd的name属性
struts.xml:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <!-- Add packages here --> <constant name="struts.devMode" value="true" /> <constant name="struts.enable.DynamicMethodInvocation" value="false"></constant> <!-- 取名与用户模块相对应 --> <!-- <package name="default" namespace="/" extends="struts-default"> --> <package name="user" namespace="/user" extends="struts-default"> <default-action-ref name="index"/> <action name="index"> <result>/index.jsp</result> </action> <action name="login" class="com.ljb.web.action.LoginAction"> <result> /loginSuccess.jsp </result> </action> </package> </struts>
login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!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>Insert title here</title> </head> <body> <form action="user/login" method="post"> 用户名:<input type="text" name="userName"/><br/> 密码:<input type="password" name="password"/><br/> 年龄:<input type="text" name="age"/><br/> <input type="submit" value="提交"/> <input type="reset" value="重置"/> </form> </body> </html>
注:路径(user/login)
小结:
3、result的type属性
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <!-- Add packages here --> <constant name="struts.devMode" value="true" /> <constant name="struts.enable.DynamicMethodInvocation" value="false"></constant> <package name="user" namespace="/user" extends="struts-default"> <default-action-ref name="index"/> <action name="index"> <result>/index.jsp</result> </action> <action name="login" class="com.ljb.web.action.LoginAction" method="login"> <result name="success"> /loginSuccess.jsp </result> <result name="input"> /login.jsp </result> </action> </package> </struts>
package com.ljb.web.action; import com.opensymphony.xwork2.ActionSupport; /** * 第一种传递参数方法(设置私有属性,设置set与get方法) * @author Administrator * */ public class LoginAction extends ActionSupport { private String userName; private String password; private int age; public int getAge() { return age; } public void setAge(int age) { this.age = age; } 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; } @Override public String execute() throws Exception { // TODO Auto-generated method stub return SUCCESS; } public String login () { if (userName.equals("admin")&&password.equals("ok")) { return SUCCESS; } else { return INPUT; } } }
标签:
原文地址:http://my.oschina.net/u/2320342/blog/414145