学习视频 : http://edu.csdn.net/course/detail/949
struts2官网 : http://struts.apache.org/
API下载地址: http://pan.baidu.com/disk/home#path=%252Fjava%25E8%25B5%2584%25E6%2596%2599%252FstrutsAPI
web.xml
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
.do表示用的是struts1,.action表示用的是struts2
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="FirstAction" class="com.hm.bozi.FirstAction">
<result name="success">success.jsp</result>
<result name="error">error.jsp</result>
</action>
</package>
</struts>
FirstAction
package com.hm.bozi;
public class FirstAction{
public String execute() throws Exception{
return "success";
}
}
success.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<p>成功了!!!!!</p>
</body>
</html>
访问:http://localhost:8080/teststruts001/FirstAction.action 页面提示:成功了!
struts2线程安全问题:struts1或者servlet只有实例,被反复的调用,struts2中的Action处理一次请求会生成一个实例,这些实例彼此完全独立,使用完毕后就立马销毁。struts1中的Action线程不安全,一般不能有可写的属性,即将Action设计成无状态类。struts2中的Action线程安全,可以随意设置属性。
struts1中的Action需要实现特定的接口,struts2中的Action相当灵活,既可以实现接口,也可以不实现仅仅只是个普通java类。