Struts2.5版本以上的struts.xml和jar包配置
来源:互联网 发布:linux网速测试工具 编辑:程序博客网 时间:2024/06/05 01:09
*Struts2.5版本以上的struts.xml和jar包配置 *
由于Struts2的版本在不断的更新,对文件的配置要求也有了一些改变。
对于Struts2.5以上的版本如果需要url+!+方法访问Action某个方法的话需要在struts.xml加入如下语句
<constant name="struts.enable.DynamicMethodInvocation" value="true"/> <constant name="struts.devMode" value="true"></constant>
以上两句是DIM(动态访问方法的配置)
有时候可以还会出现 Method 方法 for action Action is not allowed
这时候可能需要在struts.xml中package中加入继续加入如下语句
<global-allowed-methods>regex:.*</global-allowed-methods>
还有别忘了把项目的输出设置到WEB-INF下的classes文件里,如图
原因
JBoss默认从WEB-INF/目录下加载资源,Eclipse在发布程序的时候,并没有把User Libraries的相关资源拷贝到WEB-INF/目录下(Eclipse会把src目录下的所有非*.java文件复制到WEB-INF/classes目录下),所以Tomcat说找不到所需要的类
所需jar包
注意jar包一定要放在WebContent/WEB-INF/lib路径下 最后注意要build path
1、首先我们配置一下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_3_1.xsd" version="3.1"> <display-name>Struts</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.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>Struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
其中org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter过滤器是struts2.5后由org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter改过而来的
2、配置struts.xml
<span style="font-size:12px;"><?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd"> <struts> <constant name="struts.enable.DynamicMethodInvocation" value="true"/> <constant name="struts.devMode" value="true"></constant> <package name="MyPackage" namespace="/" extends="struts-default"> <global-allowed-methods>regex:.*</global-allowed-methods> <action name="first" class="UserAction"> <result name="success">first.jsp</result> <result name="add">add.jsp</result> <result name="delete">delete.jsp</result> </action> </package> </struts></span>
注意class指定是action的类名
3、UserAction类
import com.opensymphony.xwork2.ActionSupportpublic class UserAction extends ActionSupport { /** * */ private static final long serialVersionUID = 1L; private String username; private String info; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String add()throws Exception{ setInfo("添加用户"); return "add"; } public String delete()throws Exception{ setInfo("删除用户"); return "delete"; } public String getInfo() { return info; } public void setInfo(String info) { this.info = info; } }
4、index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 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> <link rel="stylesheet" type= "text/css" href="css/indescss.css"> </head> <body> <%String path = request.getContextPath(); %> <a href="first!add" >go the add page</a> <br> <a href="first!delete" >go the delete page</a> <br> <a href="first.action" >go the first page</a> <br> <a href="add" >go the add2 page</a> </body> </html>
5、delete.jsp
<span style="font-size:12px;"><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> <!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=ISO-8859-1"> <title>Insert title here</title> </head> <body> <p><s:property value="info"/></p> </body> </html></span>
6、add.jsp
<span style="font-size:12px;"><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib prefix="s" uri="/struts-tags" %> <!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> <p><s:property value="info"/></p> </body> </html> </span>
- Struts2.5版本以上的struts.xml和jar包配置
- Struts2.5版本以上的struts.xml配置
- Struts2.5版本以上的struts.xml配置
- struts2配置jar包以及struts.xml常用配置
- spring2.0和spring2.5及以上版本的jar包区别 spring jar 包详解
- spring2.0和spring2.5及以上版本的jar包区别 spring jar 包详解
- spring2.0和spring2.5及以上版本的jar包区别 spring jar 包详解
- spring2.0和spring2.5及以上版本的jar包区别 spring jar 包详解
- Struts2.5版本struts.xm和web.xml配置更改
- struts的jar包和配置
- spring2.0和spring2.5及以上版本的jar包区别
- Struts2的配置(jar包版本为2.3.8)
- Struts2的Struts.xml 补充和Struts.properties配置详解
- Struts2 在Struts.xml配置包 package
- struts2 的struts.xml配置
- struts2的struts.xml配置
- struts2 2.5以上版本安装中web.xml的配置(包括核心过滤器filter)
- 【开发过程问题汇总系列】【B/S struts2】加好jar包且配置好struts.xml后action还是无法请求的问题
- pinpoint
- Makefile的一个例子
- Android后门GhostCtrl,完美控制设备任意权限并窃取用户数据
- TP5
- hdu1045—Fire Net(二分图最大匹配)
- Struts2.5版本以上的struts.xml和jar包配置
- Java 实现ftp上传下载文件
- 33 个 2017 年必须了解的 iOS 开源库
- iOS uiimage和其它view 设置圆角的方式
- [HAOI2009]毛毛虫
- 关于accept非阻塞
- C语言(关于字符数组)
- session介绍
- 报时助手