Struts 2.1.6 Streamlined Instance Series tutorial (2): Implementation of User Login module

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.