日期:2014-05-19  浏览次数:20714 次

struts2 默认Action问题,,急啊!
struts.xml文件里的内容如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
  "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

   
  <constant name="struts.devMode" value="true" />

  <package name="default" namespace="/" extends="struts-default">
   
  <!-- 默认Action -->
  <default-action-ref name="index"></default-action-ref>
  <action name="index">
  <result>/test.jsp</result>
  </action>
  </package>
</struts>

web.xml内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<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>
  
</web-app>
该加的包也都加了,处理其他的Action都可以就是这个默认Action不可以,不知道为什么,假如项目名为PP,那么在浏览器中输入http://localhost:8080/PP之后,显示的结果还是index.jsp中的内容,我已经在web.xml中把welcome-file删了,为什么还是显示index.jsp呢,搞不懂,默认的Action为什么不执行呢,即使输入http://localhost:8080/PP/fsdfsd也不行。我把namespace=“/user”,然后输入http://localhost:8080/PP/user/还是不行,只有输入http://localhost:8080/PP/user/index时才显示test.jsp里面的内容,为什么啊,请大侠指点!

------解决方案--------------------
把web.xml里面的welcome-file中改为index
然后在工程的webcontent下建立一个index的空文件。没有扩展名。
------解决方案--------------------
看看web.xml里面的welcome-file是怎样写的,或是把index.jsp里面的内容清空,加上一句document.location.href=xxx/index
action是要有东西触发才能执行的。