赤月传说2勋章升级:struts2示例学习2-快速起步 - Struts - New - ITeye论坛
来源:百度文库 编辑:九乡新闻网 时间:2024/05/02 16:52:12
几天去sturs官网学习了一下,把示例翻译了一下,在这里和大家一起分享一下
strutsdemo学习网站
ttp://struts.apache.org/2.x/docs/simple-setup.html
Struts2学习笔记-part1: 快速起步
准备工作:
下载struts2: http://apache.mirror.phpchina.com/struts/binaries/struts-2.0.11.1-all.zip
准备Tomcat5.x
建立一个Java Web项目,提取最少运行Struts2应用的包集合(摘自Struts官方文档):
Install the Minimum Set of Libraries and Configuration Files
The following files are a minium requirement for your application.
Filename Description
struts2-core.jar Framework library itself, found in distribution root directory
xwork.jar XWork 2 library on which Struts 2 is built (version 2.0 or later)
ognl.jar Object Graph Navigation Language (OGNL), the expression language used throughout the framework
freemarker.jar All UI tag templates are written in Freemarker (also a good option for your own views)
commons-logging.jar Commons logging, which the framework uses to support transparently logging to either Log4J or JDK 1.4+
web.xml Java web application configuration file that defines the filters (and other components) for your web application
struts.xml Framework configuration file that defines the actions, results, and interceptors for your application
If any Struts 2 Plugins are included, then other JARs may be needed too. For example, the optional Spring Plugin requires the Spring JARs to be present.
目标:实现一个简单的用户登录.
下面是实现源码:
一、先实现登录页面
<%--
登录页面
User: leizhimin
Date: 2008-3-14
Time: 15:45:52
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=GBK" language="java" %>
登录页面
二、实现处理页面的Action
package stu;
/**
* 处理用户请求的Action
* File: LoginAction.java
* User: leizhimin
* Date: 2008-3-14 15:59:07
*/
public class LoginAction {
private String username;
private String password;
/**
* 处理用户请求的execute方法
* 因为Struts2的拦截机制,他们负责解析用户的请求参数,并将请求参数赋给Action对应的属性
*
* @return 当用户名为aaa并且密码为123时,返回success,否则,返回error.
* @throws Exception
*/
public String execute() throws Exception {
//当用户名为aaa并且密码为123时,返回success,否则,返回error.
if (getUsername().equals("aaa") && getPassword().equals("123")) {
return "success";
} else {
return "error";
}
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
三、配置Web.xml
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
Struts Blank
struts2
org.apache.struts2.dispatcher.FilterDispatcher
struts2
/*
/login.jsp
四、配置Action处理结果和资源资源之间的映射关系
注意:此文件打包后位于WEB-INF/classes/目录下面,或者放入classpath。
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
Struts Blank
struts2
org.apache.struts2.dispatcher.FilterDispatcher
struts2
/*
/login.jsp
五、增加登录成功和失败页面
<%@ page contentType="text/html;charset=GBK" language="java" %>
登录成功页面
登录成功!
<%@ page contentType="text/html;charset=GBK" language="java" %>
登录失败
登录失败!
六、打包并部署到tomcat,运行如下图:
strutsdemo学习网站
ttp://struts.apache.org/2.x/docs/simple-setup.html
Struts2学习笔记-part1: 快速起步
准备工作:
下载struts2: http://apache.mirror.phpchina.com/struts/binaries/struts-2.0.11.1-all.zip
准备Tomcat5.x
建立一个Java Web项目,提取最少运行Struts2应用的包集合(摘自Struts官方文档):
Install the Minimum Set of Libraries and Configuration Files
The following files are a minium requirement for your application.
Filename Description
struts2-core.jar Framework library itself, found in distribution root directory
xwork.jar XWork 2 library on which Struts 2 is built (version 2.0 or later)
ognl.jar Object Graph Navigation Language (OGNL), the expression language used throughout the framework
freemarker.jar All UI tag templates are written in Freemarker (also a good option for your own views)
commons-logging.jar Commons logging, which the framework uses to support transparently logging to either Log4J or JDK 1.4+
web.xml Java web application configuration file that defines the filters (and other components) for your web application
struts.xml Framework configuration file that defines the actions, results, and interceptors for your application
If any Struts 2 Plugins are included, then other JARs may be needed too. For example, the optional Spring Plugin requires the Spring JARs to be present.
目标:实现一个简单的用户登录.
下面是实现源码:
一、先实现登录页面
<%--
登录页面
User: leizhimin
Date: 2008-3-14
Time: 15:45:52
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=GBK" language="java" %>
二、实现处理页面的Action
package stu;
/**
* 处理用户请求的Action
* File: LoginAction.java
* User: leizhimin
* Date: 2008-3-14 15:59:07
*/
public class LoginAction {
private String username;
private String password;
/**
* 处理用户请求的execute方法
* 因为Struts2的拦截机制,他们负责解析用户的请求参数,并将请求参数赋给Action对应的属性
*
* @return 当用户名为aaa并且密码为123时,返回success,否则,返回error.
* @throws Exception
*/
public String execute() throws Exception {
//当用户名为aaa并且密码为123时,返回success,否则,返回error.
if (getUsername().equals("aaa") && getPassword().equals("123")) {
return "success";
} else {
return "error";
}
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
三、配置Web.xml
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
四、配置Action处理结果和资源资源之间的映射关系
注意:此文件打包后位于WEB-INF/classes/目录下面,或者放入classpath。
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
五、增加登录成功和失败页面
<%@ page contentType="text/html;charset=GBK" language="java" %>
登录成功!
<%@ page contentType="text/html;charset=GBK" language="java" %>
登录失败!
六、打包并部署到tomcat,运行如下图:
参考资料:
http://struts.apache.org/2.x/docs/simple-setup.html
struts权威指南
本文出自"andyjames"博客,转载请与作者联系!谢谢!
struts2示例学习2-快速起步 - Struts - New - ITeye论坛
DOS命令大全(经典收藏) - New - ITeye论坛
struts2.0之struts.xml
Struts2的配置文件——struts.xml
17.7 使用Struts2 注释验证 - struts2 - ITeye专栏频道
ActiveX控件打包成Cab置于网页中自动下载安装 - 入门技术 - New - ITeye论坛
请问如何用java获取这些系统参数? - New - ITeye论坛
MyEclipse Struts 快速
Struts2教程3:struts.xml常用配置解析
struts2学习总结
struts2.x学习总结
Struts学习笔记(一)
Apache Struts - Key Technologies Primer struts学习前得基础
Struts2、Spring、Hibernate三者整合的过程示例
Spring Struts Hibernate快速入门实例
Coding Struts 2 Actions
Struts 2 的国际化
Struts2配置文件详解——struts-default.xml - StarStream的日志 - 网易博客
艺术零起步-教你怎样画画(快速素描学习入门教程)附视频_
z艺术零起步-教你怎样画画(快速素描学习入门教程)附视频
艺术零起步-教你怎样画画(快速素描学习入门教程)
艺术零起步-教你画画(快速素描学习入门教程)附视频
艺术零起步-教你怎样画画( 快速素描学习入门教程)附视频
艺术零起步-教你样画画(快速素描学习入门教程)附视频