快速搭建struts2框架

快速搭建struts2框架

1.下载struts2源码包,官方网址:https://struts.apache.org/download.cgi#struts2516
这里写图片描述
2.创建一个web工程项目
这里写图片描述
3.打开struts2源码包的lib文件夹,选择需要的jar包:
commons-io
commons-lang3
commons-fileupload
javassist
struts2-core
xwork-core
freemarker
ognl
4.将所需jar包拷贝到lib目录下:
这里写图片描述
5.在src下创建名字为struts.xml的配置文件,在struts2-core的jar包下有一份xml的dtd校验文件:
这里写图片描述
这里写图片描述
这里写图片描述
6.在web.xml中配置struts2启动过滤器:

<!-- 配置struts2启动过滤器 -->
 <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>*.do</url-pattern>
 </filter-mapping>

7.在WEB-INF下创建一个测试的jsp文件hello.jsp(WEB-INF下的页面是不能直接访问的):

<%@ 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>Insert title here</title>
</head>
<body>
<b>你好!欢迎使用struts2框架</b>
</body>
</html>

8.创建一个HelloAction类

package com.xxj.action;

/**
 * 测试struts2框架
 * @author aloys
 *
 * @date 2018年7月28日 下午3:22:04
 */
public class HelloAction {

	public String sayHello(){
		
		return "success";
	}
}

9.在struts.xml配置文件中进行请求后缀的更改(默认请求后缀是action),配置action

<!-- 更改请求默认后缀 -->
	<constant name="struts.action.extension" value="do"></constant>

	<package name="default" extends="struts-default" namespace="/hello">
		<action name="hello" class="com.xxj.action.HelloAction" method="sayHello">
			<result name="success">/WEB-INF/hello.jsp</result>
		</action>
	
	</package>

10.发布项目到服务器,启动,访问地址:http://localhost:8081/StrutsDemo/hello/hello.do运行成功
这里写图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值