MyEclipse2014配置2.5版本的struts2

原创


配置struts2一般来说需要以下步骤:

  • 将项目所需要的Jar包导入项目webRoot/WEB-INF/lib下(包不追求多,容易导致冲突或者其他问题,需要多少导入多少)
  • 配置struts.xml文件
  • 配置web.xml文件

2.5版本的struts2 链接:https://pan.baidu.com/s/1KnEh3UvucUvjHV9P4yTKNw 密码:kssr

在MyEclipse2014中可以按如下步骤进行配置:

一、

解压上面的压缩包

进入apps解压struts2-rest-showcase.war,解压后进入apps\struts2-rest-showcase\WEB-INF\lib下将以下9个包拷贝进入项目的webRoot/WEB-INF/lib下

如果自己项目需要更多的包可选择更多

二、

将目录apps\struts2-rest-showcase\WEB-INF\src\java下的struts.xml文件拷贝到本身项目src下面

配置完后修改struts.xml文件

<package name="rest-showcase" extends="struts-default">
     <global-allowed-methods>index,show,create,update,destroy,deleteConfirm,edit,editNew</global-allowed-methods>
        <action name="outPut" class="Action.hello">
            <result name="helloWorld">/index.jsp</result>
        </action>
</package>

三、

然后修改web.xml文件

<filter>
      <filter-name>struts2</filter-name>
      <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>/*</url-pattern>
  </filter-mapping>
对于org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter,有些旧版本的struts2可能是
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
index.jsp的内容如下:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <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>
    第一个Struts2<br>
  </body>
</html>

对于struts.xml的一些参数讲解看:https://blog.csdn.net/qq_25827845/article/details/53205941

22:07:57

2018-11-07

转载于:https://www.cnblogs.com/chiweiming/p/9926108.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值