struts2发布时报错404
我是个超级新手,看了好多都是说路径问题,但是我还是不会调,能不能指条明路?ACTION是放在了一个叫com的包里,然后工程名是FirstTest,请问我需要改进哪里?非常感谢。
这是stuts.xml页面:
<package name="body" extends="struts-default" namespace="/">
		<action name="/com/NewsList" class="com.NewsAction" method="getAllNews">
			<result name="index">/WEB-INF/jsp/index.jsp</result>
		</action>
这是web.jsp代码:
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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">		
	<!-- Spring config file -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>/WEB-INF/appctx.xml</param-value>
	</context-param>
	<!--Startup spring-->
	<listener>
		<listener-class>			
org.springframework.web.context.ContextLoaderListener		</listener-class>
	</listener>		
	<!-- Config struts2 filter -->
	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>
			org.apache.struts2.dispatcher.FilterDispatcher
		</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>	
   <welcome-file-list>
     <welcome-file>index.jsp</welcome-file>
   </welcome-file-list>
</web-app>
这是index.jsp的部分内容:
<body>
   <s:form name="NewsList"  action="/com/NewsList.do" >
    	<center><br />
    	<h2>NEWSLIST</h2>    	
    	<table border="1">
    	<tr bgcolor="#33CCFF">
    	   <td align="center">NEWSID</td>
    	   <td align="center">NEWSTITLE</td>
    	   <td align="center">NEWSCONTENT</td>
    	   <td align="center">NEWSLASTTIME</td>
    	   <td align="center">EDITNEWS</td>
    	   <td align="center">DELETNEWS</td>
    	</tr>
------解决方案--------------------你是第一次访问就报404吗?那你看下web目录下面是不是有index.jsp文件
但是看你struts.xml里面配的index.jsp文件又是放在/WEB-INF/jsp/目录下面的,我不太清楚你是不是两个目录下面都有index.jsp文件,但如果不是,建议你在web目录下放一个index.jsp
------解决方案--------------------你写的有点乱哦,3个问题:
1.你把stuts.xml和index.jsp中的action都改成NewsList.action
2.你要确定web-inf/jsp文件夹下面要有index.jsp
3(也是最重要的)struts默认拦截*.action,对于新手,你最好<url-pattern>*.action</url-pattern>
然后估计就没问题了
------解决方案--------------------  <s:form name="NewsList" action="/com/NewsList.do" >    
后面不需要加.do
------解决方案--------------------<action name="/com/NewsList" class="com.NewsAction" method="getAllNews">
name属性中最好别用/,改成其他的
比如
<action name="NewsList" class="com.NewsAction" method="getAllNews">