<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>login</title>
</head>
<form action="login.action" method="post">
用户名:
<input type="text" name="username" />
<br>
密码
<input type="password" name="password" />
<br>
<input type="submit" value="提交" />
</form>
</body>
</html>
private String username;
private String password;
return username;
}
this.username = username;
}
return password;
}
this.password = password;
}
return "success";
}
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="struts2" extends="struts-default">
<action name="login" class="test.action.LoginAction">//设置表单提交的Action
<result name="success">/welcome.jsp</result> //成功时跳转到的页面
</action>
</package>
<html>
<head>
<title>My JSP 'welcome.jsp' starting page</title>
</head>
username:${requestScope.username} password:${requestScope.password}
</body>
</html>