系统学习struts2

学习视频 :  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类。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值