《精通struts2实用教程》学习笔记-01
来源:互联网 发布:看图编辑软件 编辑:程序博客网 时间:2024/05/21 17:13
开篇说明:
本系列的笔记是根据《精通struts2实用教程》而来。
好了,开始今天的《精通struts2实用教程》学习笔记-01。(因为第一章是介绍struts2的来源,并没有涉及到实际操作,故从第二章开始。)
开发工具为Eclipse (Version: Luna Release (4.4.0))
1、下载struts2
开发前,需要下载struts2: 25页中有提到下载网址:http://struts.apache.org/download.cgi#Struts206 现在的struts2版本已经到了2.3.16.3了;或者点这个直接下载
2、创建第一个简单struts工程
3、修改WEB-INFO下的web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_ID" version="2.4"<span style="white-space:pre"></span>xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<span style="white-space:pre"></span>xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"><span style="white-space:pre"></span><!-- <display-name>Struts Blank</display-name> --><span style="white-space:pre"></span><filter><span style="white-space:pre"></span><filter-name>struts2</filter-name><span style="white-space:pre"></span><filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class><span style="white-space:pre"></span></filter><span style="white-space:pre"></span><filter-mapping><span style="white-space:pre"></span><filter-name>struts2</filter-name><span style="white-space:pre"></span><url-pattern>/*</url-pattern><span style="white-space:pre"></span></filter-mapping><span style="white-space:pre"></span><welcome-file-list><span style="white-space:pre"></span><welcome-file>login.jsp</welcome-file><span style="white-space:pre"></span></welcome-file-list></web-app>
4、往lib添加jar包
5、应用到工程中。
6、创建类LoginAction
package struts2simple.login;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(){if (getUsername().equals("scott") && getPassword().equals("tiger")) {return "success";} else {return "error";}}}
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="struts2simple" extends="struts-default"><action name="Login" class="struts2simple.login.LoginAction"><result name="error">WEB-INF/error.jsp</result><result name="success">WEB-INF/welcome.jsp</result></action></package></struts>
8、在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>登陆</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>
9、在WEB-INF添加welcome.jsp error.jsp
welcome.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>成功登陆</body></html>
<%@ 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>登陆错误</body></html>
10、运行测试:
http://localhost:8080/struts2simple/
0 0
- 《精通struts2实用教程》学习笔记-01
- struts2简单实用教程
- struts2.01学习笔记
- struts2.01学习笔记!
- Struts2学习笔记01
- Struts2学习笔记-01
- Struts2学习笔记01
- Struts2学习笔记01
- C#入门到精通学习笔记01
- 《精通Android3》学习笔记
- 精通javascript学习笔记
- Java语言实用教程笔记
- struts2框架学习笔记01
- struts2框架学习笔记01
- 精通Android4学习笔记-intent
- 精通andoird4学习笔记-service
- 《精通正则表达式》学习笔记
- 《精通正则表达式》学习笔记
- HDU 1729
- 题解HDU1026
- so库的性能注意事项
- AdaBoost的人脸识别—Haar特征与积分图
- NYOJ 821 简单求值【简单题】
- 《精通struts2实用教程》学习笔记-01
- Linux修改用户的操作权限
- js数组操作
- HDOJ题目3038 How Many Answers Are Wrong(带权值并查集)
- 《高可用MySQL》2 – 单机版MySQL主从配置
- 取消 CDockablePane 自动保存界面配置到注册表
- css颜色渐变
- 机器学习:特征工程之特征选择和学习
- Codeforces Round #273 (Div. 2)D dp