Java web从入门到放弃(5)

struts配置问题。参考了以下两个链接

http://blog.csdn.net/ws11352369/article/details/39190059

https://www.cnblogs.com/gulvzhe/archive/2011/11/21/2256632.html

配置好之后的效果如下图



需要将WEB-INF目录下的lib文件夹里面的所有jar加入buildpath

然后编辑web.xml文件加入以下内容

<!--Struts2过滤器 -->
	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
	</filter>
	<!--Struts2过滤器映射 -->
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

然后在编写truts.xml文件

<!DOCTYPE struts PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
 "http://struts.apache.org/dtds/struts-2.3.dtd" >
<struts>
	<package name="default" extends="struts-default">
		<action name="first">
			<result>/first.jsp</result>
		</action>
	</package>
</struts>

最后是两个jsp的测试页面

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="first.action">请求Struts</a>
</body>
</html>
和first.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<p>第一个struts2程序</p>
</body>
</html>

成功结果如下


点击链接之后会跳转到下图界面







在后面的过程中遇到了如下报错

There is no Action mapped for namespace [/] and action name [UserAction!add] associated with context path [/Struts01].

上网查了好久都没有解决。最终在一个大兄弟那里找到了解决方案。

在Struts2.3.x或更高的某些版本时出现There is no Action mapped for namespace [/user] and action name [user!add] associated with context path错误,原因是(1)DMI可能导致安全问题(2)DMI与通配符方法功能有重叠,因此该版本Struts2默认关闭DMI,需要在struts.xml中加一句<constant name="struts.enable.DynamicMethodInvocation" value="true" /> 来打开动态方法调用。动态方法调用官方推荐的做法是,使用通配符的形式。(但是我现在还不明白这个通配符形式是什么形式)

给出这个大兄弟的连接http://blog.csdn.net/roney_win/article/details/46575205



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值