一、功能:通过login.jsp页面登录,在result.jsp页面显示登录信息。
二、步骤:
1、下载struts2 http://struts.apache.org/download.cgi#struts210 ,使用的版本是:struts-2.0.14,解压缩。
2、在eclipse下建立 Dynamic Web Project
3、将 commons-logging-1.0.4.jar、freemarker-2.3.8.jar、ognl-2.6.11.jar、struts2-core-2.0.14.jar、xwork-2.0.7.jar 包拷贝到 WEB-INF/lib 目录下。
4、在WebContent目录下建立 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>Struts 登录</title> </head> <body> <form action="login.action" method="post"> <div> <label>用户名:</label> <input type="text" name="userName"> </div> <div> <label>密码:</label> <input type="password" name="password"> </div> <div><input type="submit" value="登录"></input></div> </form> </body> </html>
5、配置 web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>MyStruts</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <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>
6、在 src目录下建立包 wuyechun.mystruts.action ,新建文件 LoginAction.java 。
package wuyechun.mystruts.action; public class LoginAction { private String userName; private String password; 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; } public String execute() throws Exception{ return "success"; } }
7、在src 目录下新建 struts.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="strut2" extends="struts-default"> <action name="login" class="wuyechun.mystruts.action.LoginAction"> <!--<result>/result.jsp</result> --> <result name="success">/result.jsp</result> </action> </package> </struts>
8、在WebContent目录下建立 result.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>登录结果</title> </head> <body> <div><label>用户名:</label>${requestScope.userName}</div> <div><label>密码:</label>${requestScope.password}</div> </body> </html>
三、注意:
1、<form action="login.action" method="post"> 和
<action name="login" class="wuyechun.mystruts.action.LoginAction">
对应关系。
四、登录显示登录结果。
附:
<package name="login" namespace="/login" extends="default"> <!-- 系统登录 --> <action name="findLogin" method="findLogin" class="ustcsoft.hrlogin.st.HrLoginAction"> <result name="success">/FrameSet/Main.jsp</result> <result name="input" >/index.jsp</result> <result name="error">/error.jsp</result> </action> <!-- 当前登录人员的功能菜单 --> <action name="findQtyModule" method="findQtyModule" class="ustcsoft.hrlogin.st.HrLoginAction"></action> <action name="loginOut" method="loginOut" class="ustcsoft.hrlogin.st.HrLoginAction"> <result name="success" >/index.jsp</result> <result name="error">/error.jsp</result> </action> </package>
public class HrLoginAction extends AbstractAction { //登录 public String findLogin() { //用户名以及密码验证 if(!isCheckd){ return INPUT; } // String com.opensymphony.xwork2.Action.SUCCESS = "success" return SUCCESS; } //获取用户模块 public void findQtyModule() { } //退出 public String loginOut() { }
相关推荐
struts2学习笔记总结
Struts2学习笔记,介绍了struts2的基础部分
struts2学习笔记,非本人所写,但有学习的价值,总结的很好,分享一个!
1. struts2框架的引入 1)把struts2的相关jar包导入到项目中去 2)把struts2框架的配置文件struts.xml复制粘贴到项目中的src下面(同时也可以把log4j.properties放到src下) 在这里我们主要是要的这个struts.xml文件...
这是学习struts2时记得重点笔记,包括了一些原理,ognl语句的编写,以及如何设置拦截器等等一些基本知识,起到复习和巩固的作用
struts2学习笔记struts2学习笔记struts2学习笔记
struts2学习笔记3数据类型转换struts2学习笔记3数据类型转换struts2学习笔记3数据类型转换struts2学习笔记3数据类型转换struts2学习笔记3数据类型转换struts2学习笔记3数据类型转换struts2学习笔记3数据类型转换
本人学习struts2的笔记,希望大家可以多多学习以后共同交流
NULL 博文链接:https://myeportfolio.iteye.com/blog/566259
namespace :对应与项目名称后面的"/"(例如Struts2_0100_Introduction后面的"/") (http://localhost:8080/Struts2_0100_Introduction/) 四、 标签 是用来解决重名的问题,例如当系统的前台和后台都有一个action...
structs2很详细的学习笔记,structs2的建造,工作原理,例子,逐步讲解,纯文字的
struts2四天的学习笔记。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
struts2.0学习笔记1 自己动手做的还算可以的 ]struts2.0学习笔记1 自己动手做的还算可以的struts2.0学习笔记1 自己动手做的还算可以的struts2.0学习笔记1 自己动手做的还算可以的
个人收藏,纯属备份作用,做个记录,方便需要时候查看
Struts2 学习笔记.doc,Struts2 学习笔记.doc