Structs2相关介绍及简单执行

一、struts2是什么
struts2是J2EE的比较流行的框架,对JSP/servlet进行了封装,应用于面向WEB开发的项目。struts是MVC设计模式的一种解决方案.
二、struts2与struts1的区别
struts1在2001年诞生,是web开发中MVC设计模式的一种解决方案.webwork随后诞生,是更为灵活合理的MVC框架。struts2是在webwork的基础上的升级,只是命名沿用。
1.Action实现:struts1继承抽象的父类,struts2不需要。
2.Action实例化:struts1中Action是单例模式,struts2为多实例。
3.与jsp/Servlet耦合:struts1调用传统的jsp/servletAPI,struts2重新封装了API(与jsp/servlet无关),实现解耦。
4.测试方面:因为struts1仍然调用servlet的API,因此测试必须依赖于web服务器,但struts2脱离服务器测试。
5.表达式语言:struts1整合了JSTL,struts2则整合了更为强大的OGNL表达式。
总之struts2与struts1除了命名之外,其实没有多大关系。
三、下载
地址:http://struts.apache.org/
在这里插入图片描述
在这里插入图片描述
保存到自己想要保存的位置即可。
这里插入图片描述
四、介绍
1、解压
在这里插入图片描述
2、jar包介绍
在这里插入图片描述
在这里插入图片描述
3、必须包
在这里插入图片描述
五、开发环境搭建
1、创建Dynamic Web Project
在这里插入图片描述
在这里插入图片描述
2、tomcat和jre的配置
在这里插入图片描述
3、拷贝jar包
在这里插入图片描述
4、配置web.xml的过滤器

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
  <display-name>struts2</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
<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>

</web-app>

5、写HelloAction
在这里插入图片描述
在这里插入图片描述

package com.tong.action;

public class HelloAction {
	public String execute() {
		System.out.println("HelloAction.execute()");
		return "success";
	}
}

6、src下写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>

    <constant name="struts.devMode" value="true" />

    <package name="test" namespace="/" extends="struts-default">

               <action name="hello" class="com.tong.action" method="execute">
            <result name="success">/HelloWorld.jsp</result>
        </action>
    </package>

    

</struts>


7、在WebContent下写HelloWorld.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>
<base href="${pageContext.request.contextPath}/">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
hello World jsp
</body>
</html>

执行即可
在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值