<%@ page language="java" contentType="text/html; charset=GBK"%>
<html>
<head>
<title>登录页面</title>
</head>
<body>
<!-- 提交请求参数的表单 -->
<form action="Login.action" method="post">
<table align="center">
<caption><h3>用户登录</h3></caption>
<tr>
<!-- 用户名的表单域 -->
<td>用户名:<input type="text" name="username"/></td>
</tr>
<tr>
<!-- 密码的表单域 -->
<td>密 码:<input type="text" name="password"/></td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" value="登录"/><input
type="reset" value="重填" /></td>
</tr>
</table>
</form>
</body>
</html>
Struts 2 Action默认拦截所有后缀为.action的请求。因此,如果我们需要将某个表单提交给Struts 2 Action
处理,则应该将该表单的action属性设置为*.action的格式。
对于Action中的属性参数,表面上看起来,该Action的属性只提供了对应的setter和getter方法,很难理解请求参数在什么时候赋值给该Action的属性,事实上,因为Struts 2的拦截器机制,它们负责解析用户的请求参数,并将请求参数赋值给Action对应的属性。所以,在Action中只需要调用该Action中的属性既可以了,而不需要使用Request来获取。