User login is almost every required module of each Web system, this tutorial will explain Struts2.1.6 action and result annotation configuration through user Login module.
Struts 2.1.6 in the previous series tutorial (1): The setting up of the environment and the hellosimple, we built the package named "Cn.simple.action", these package names have a rule, as long as contains "action,actions, Struts,struts2 "will be scanned by default to the action class, which means that we simply configure the package name such as" Cn.simple.action "," cn.simple.struts "," Cn.simple.action.admin " , you can not configure these action classes in the configuration file Struts.xml (Struts2.0 configuration file). Of course, these package names, can also be other, but to write a little bit configuration, we use the default bar. Regarding this aspect detailed explanation, still strongly recommends that everybody read the official document Http://struts.apache.org/2.1.6/docs/convention-plugin.html first.
OK, let's start writing our user Login module. First write a loginform.jsp, remember, don't forget we put the JSP file in the web-inf/content/directory
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录页</title>
<body>
<s:fielderror></s:fielderror>
<form action="login.action" method="post">
账号<input type="text" name="loginName" value="${loginName}"/><br/>
密码<input type="password" name="password"><br/>
<input type="submit" value="登录"/>
</form>
</body>
If you want to use Struts 2 tag library, you can also use the Struts 2 form label, before using the JSP header configuration on the Struts 2 tag library, replaced by the Struts 2 label version, namely:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<body>
<s:fielderror></s:fielderror>
<s:form action="login">
<s:textfield name="loginName"></s:textfield>
<s:password name="password"></s:password>
<s:submit value="登录"></s:submit>
</s:form>
</body>