MyEclipse2014配置2.5版本的struts2

时间:2018-11-07 23:01:02   收藏:0   阅读:900

原创


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

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

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!