我是刚接触Struts2,开门就遇到了难题,我想从一个界面输入一个姓名,通过action把姓名从另一个界面输出来,但一点击submit就出现404错误,调了两天也没调出来,真是快郁闷死了,望各位高手给予指导,不胜感激
代码如下:
  配置文件:
jar包:
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
commons-logging-1.0.4.jar
freeer-2.3.8.jar
ognl-2.6.11.jar
struts2-core-2.1.8.1.jar
xwork-core-2.1.6.jar
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>struts</display-name>
  <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>PastP.jsp</welcome-file>
    </welcome-file-list>
</web-app>
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>
    <include file="struts-default.xml"/>
    <package name="struts2" extends="struts-default">
        <action name="hello" class="struts.test.Hello">
            <result>result.jsp</result>
        </action>
    </package>
</struts>
PostP.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>To past paramter</title>
</head>
<body>
<h2>please input you name:</h2>
<form action="hello.action" method="post">
<input type="text" name="name"></input><br></br>"
<input type="submit" value="snbmit" align="right"/><input type="reset" value="reset"align="left"></form>
</body>
</html>
action    Hello.java:
package test;import com.opensymphony.xwork2.ActionSupport;@SuppressWarnings("serial")
public class Hello extends ActionSupport {
private String name; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
public String execute(){
return "success";
}
}
result.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>come to the result</title>
</head>
<body>
<h2>Hello to you!</h2>
${name}
</body>
</html>Tomcat运行日志:
2010-3-3 15:40:19 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:FirstTest' did not find a matching property.
2010-3-3 15:40:19 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Struts2_HelloWorld' did not find a matching property.
2010-3-3 15:40:19 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:struts' did not find a matching property.
2010-3-3 15:40:19 org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:\Ruby\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Intel\DMIX;C:\Program Files\Common Files\Thunder Network\KanKan\Codecs;d:\Program Files\Subversion\binE:\mysql-5.1.39-win32\bin;e:\Ora10InstantClient
2010-3-3 15:40:19 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2010-3-3 15:40:19 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 827 ms
2010-3-3 15:40:19 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2010-3-3 15:40:19 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.18
2010-3-3 15:40:20 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider register
信息: Parsing configuration file [struts-default.xml]
2010-3-3 15:40:21 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider register
信息: Parsing configuration file [struts-plugin.xml]
2010-3-3 15:40:21 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider register
信息: Parsing configuration file [struts.xml]
2010-3-3 15:40:21 org.apache.struts2.config.Settings getLocale
警告: Settings: Could not parse struts.locale setting, substituting default VM locale
2010-3-3 15:40:21 com.opensymphony.xwork2.util.ObjectTypeDeterminerFactory <clinit>
信息: Setting DefaultObjectTypeDeterminer as default ...
2010-3-3 15:40:22 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider register
信息: Parsing configuration file [struts-default.xml]
2010-3-3 15:40:22 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider register
信息: Parsing configuration file [struts-plugin.xml]
2010-3-3 15:40:22 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider register
信息: Parsing configuration file [struts.xml]
2010-3-3 15:40:22 org.apache.struts2.config.Settings getLocale
警告: Settings: Could not parse struts.locale setting, substituting default VM locale
2010-3-3 15:40:22 com.opensymphony.xwork2.util.ObjectTypeDeterminerFactory <clinit>
信息: Setting DefaultObjectTypeDeterminer as default ...
2010-3-3 15:40:22 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-default.xml]
2010-3-3 15:40:23 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Unable to locate configuration files of the name struts-plugin.xml, skipping
2010-3-3 15:40:23 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-plugin.xml]
2010-3-3 15:40:23 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Unable to locate configuration files of the name struts.xml, skipping
2010-3-3 15:40:23 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts.xml]
2010-3-3 15:40:23 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2010-3-3 15:40:23 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2010-3-3 15:40:23 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/78  config=null
2010-3-3 15:40:23 org.apache.catalina.startup.Catalina start
信息: Server startup in 4106 ms

解决方案 »

  1.   


    Java代码 
    The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path:    
    /usr/local/jdk/jdk1.5.0_15/jre/lib/i386/client:   
    /usr/local/jdk/jdk1.5.0_15/jre/lib/i386:   
    /usr/local/jdk/jdk1.5.0_15/jre/../lib/i386  The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: 
    /usr/local/jdk/jdk1.5.0_15/jre/lib/i386/client:
    /usr/local/jdk/jdk1.5.0_15/jre/lib/i386:
    /usr/local/jdk/jdk1.5.0_15/jre/../lib/i386
    解决这个问题的方法 
    方法一 
    1  在网上下一个tcnative-1.dll文件 
       下载   http://tomcat.heanet.ie/native/1.1.2/binaries/win32/tcnative-1.dll  
       
    2  然后复制到C:\windows\system32下面或者放在tomcat\bin里  
       
    3  重起tomcat。   
    方法二 Tomcat启动的时候出现下面这样的提示: Java代码 
    2006-1-26 19:44:11 org.apache.catalina.core.AprLifecycleListener lifecycleEvent   
    信息: The Apache Tomcat Native library which allows optimal performance in production    
    environments was not found on the java.library.path: D:\Java\jdk1.5.0_05\bin;   
    .;C:\WINDOWS\system32;C:\WINDOWS;d:\ruby\bin;.;..;D:\Java\jrockit-R26.0.0-jdk  2006-1-26 19:44:11 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
    信息: The Apache Tomcat Native library which allows optimal performance in production 
    environments was not found on the java.library.path: D:\Java\jdk1.5.0_05\bin;
    .;C:\WINDOWS\system32;C:\WINDOWS;d:\ruby\bin;.;..;D:\Java\jrockit-R26.0.0-jdk这是建议使用apache的apr。 
    详情见 http://tomcat.apache.org/tomcat-5.5-doc/apr.html 问题搜索页面:http://www.google.com/search?hl=zh-CN&newwindow=1&q=The+Apache+Tomcat+Native+library+which+allows+optimal+performance&btnG=%E6%90%9C%E7%B4%A2&lr= 
      

  2.   

    <action name="hello" class="struts.test.Hello"> 
                <result>result.jsp </result> 
            </action>
    你的action的包名是test,怎么写成struts.test了,晕
      

  3.   

     <action name="hello" class="struts.test.Hello">
      <result>result.jsp</result>
      </action>
    这句话还没有指定方法怎么找的到
      

  4.   

    在这里<form action="/123/Hello.action" method="post">
    这里的/123是你的项目根目录
    还有就是
    <%
    String path=request.getContextPath();
    %>
    后面写成
    <form action="/<%=path%>/Hello.action" method="post">
    这样也是不行的,具体什么原因我还弄不清楚
    我开始也遇到了你的那种情况,用上面的第一种方法解决了!!希望能帮到你!
      

  5.   

    补充一下,在struts.xml中我用的是默认的包,如果不是的话,你还得加上包名