最近开始学习struts2,建了个练习的项目,然而出手就卡死,index.jsp和success.jsp都可以直接访问,
但是问什么访问helloworld.action就404,跳转直接访问都不行,新手,求大神,妈的我传了6个图,为什么只有1张,我擦,我用手机根本看不到图,
![![![![![
由于看不到图,我再贴一次
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
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>helloword</title>
</head>
<body>
sdfasdfasdfasdfa
<a href="${pageContext.request.contextPath }/helloworld.action">6666666</a>
</body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
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>
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- 指定Struts2配置文件的DTD信息 -->
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<!-- Struts2配置文件的根元素 -->
<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";
}
}
贴个源码看看,一般都是路径没有配好
tomcat的server.xml中加了对应的模块的资源映射
可能是path=”/vweb” 与struts2的路径/vweb/view/vweb.action相冲突。
于是修改之:
兄弟,不要structs了,很少用了 赶紧转到Spring大家庭吧
1.web.xml中添加struts2的filter
<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>
2.HelloWorldAction.java里写一个helloworld()方法
public String helloworld(){
return SUCCESS;
}
3.struts.xml配置action
<package name="hello" extends="struts-default">
<!-- 定义处理请求URL为helloworld.action的Action -->
<action name="helloworld" class="com.struts.action.HelloWorldAction">
<!-- 定义处理结果字符串和资源之间的映射关系 -->
<result name="success">/success.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
4.访问路径:项目路径+/helloworld
(因为在web.xml中设置的是/*,所以后面不用.action了)
现在都用springboot了
filter和struts.xlm都适配好了吗,地址栏真的发出了action请求吗看看