日期:2014-05-18  浏览次数:20693 次

新手求助...struts2的配置问题
配置问题~
我想在index页面输入2个数字,等于0就跳到zero.jsp,等于1就到one.jsp,其他就到other.jsp。
①我下载了struts2,并把所有的jar包都丢到了WEB-INF的lib下.
②在WEB-INF下创建了一个web.xml内容如下:
<?xml version="1.0" encoding="gbk"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>JspWebTest</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>HelloWorld.jsp</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <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>
③我在WEB-INF下建立了一个classes,并且创建了一个struts.xml..内容:
<struts>
<package name="package" extends="struts-default">
<action name="sum" class="ch3.SumTest">
<result name="ZERO">/zero.jsp</result>
<result name="ONE">/one.jsp</result>
<result name="OTHERS">/others.jsp</result>
</action>
</package>
</struts>
④我在工程ch3目录下的ch3包下创建了一个类,名字叫SumTest.java
package ch3;

import com.opensymphony.xwork2.ActionSupport;

public class SunTest extends ActionSupport
{
int o1;
int o2;
public String execute()
{
if(o1+o2==0)
return "ZERO";
if(o1+o2==1)
return "ONE";
else
return "OTHERS";
}
public int getO1()
{
return o1;
}
public void setO1(int o1)
{
this.o1 = o1;
}
public int getO2()
{
return o2;
}
public void setO2(int o2)
{
this.o2 = o2;
}
}
⑤我在WebContent目录下建立了index.jsp ,   one.jsp等等.....
index.jsp中body部分内容:
<body>
<s:form action="sum">
<s:textfield name="o1"/>
<s:textfield name="o2"/>
<s:submit value="go~"/>
</s:form>
</body>

然后我在eclipse中运行index.jsp就提示
HTTP Status 404 - /ch3/index.jsp

--------------------------------------------------------------------------------

type Status report

message /ch3/index.jsp

description The requested resource is not available.

为什么呀?!哪里弄错了?!
------解决方案--------------------
struts.xml应该放在工程下的src里
在WebRoot目录下建立了index.jsp ,   one.jsp等

<struts>
<package name="package" extends="struts-default">
在上面package里加上namespace=“ch3”