最近开始学习struts2,建了个简单练习,然而,action控制器总是404,弄了好久了
,直接访问webcontent下的jsp文件是可以的,但是这个action总是有毒!!求大神
刚刚发了一次悬赏,但是不知道怎么的,根本看不到代码,逼我再发一次。
index.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>helloword</title>
</head>
<body>
sdfasdfasdfasdfa
<a href="${pageContext.request.contextPath }/helloworld.action">6666666</a>
</body>
</html>
web.xml
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Struts Blank</display-name>
<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>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<!-- Restricts access to pure JSP files - access available only via Struts action -->
<security-constraint>
<display-name>No direct JSP access</display-name>
<web-resource-collection>
<web-resource-name>No-JSP</web-resource-name>
<url-pattern>*.jsp</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>no-users</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<description>Don't assign users to this role</description>
<role-name>no-users</role-name>
</security-role>
</web-app>
struts.xml
<struts>
<!-- Struts2的Action必须放在指定的包空间下定义 -->
<package name="hello" extends="struts-default" namespace="/*">
<!-- 定义 action,该action对应的类为cn.itcast.action.HelloWorldAction类
-->
<action name="helloworld" class="cn.itcast.action.HelloWorldAction">
<!-- 定义处理结果和视图资源之间的映射关系 -->
<result name="success">/success.jsp</result>
</action>
</package>
</struts>
HelloWorldAction.java
package cn.itcast.action;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorldAction extends ActionSupport{
public String execute() throws Exception{
System.out.println("dddddd");
int i=0;
return "success";
}
}
最后加个目录结构