两个问题同时问一下:
我使用的myeclipse7.5,tomcat6,jdk1.6.0_18,struts-2.2.3;
1、404的问题:
初学struts,按照书上的指导,首先建立了名为test的web应用在tomcat的webapps下,其中test\WebRoot\WEB-INF\lib下拷入了基本jar包,并在java build path 中导入了,
在test\WebRoot\WEB-INF中的web.xml里配置如下 <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>在test\src中的struts.xml里的配置如下<!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.i18n.encoding" value="gb2312"/>
<include file="struts-default.xml"/>
<package name="action" extends="struts-default">
<action name="showWords" class="action.ShowWords">
<result name="success">showWords.jsp</result>
<result name="input">inputWords.jsp</result>
</action>
</package>
</struts>之后在test\src下建立了action包,里面编写了ShowWords.java(同时在WEB-INF\class\action中生成相应的.class文件),代码如下package action;import com.opensymphony.xwork2.ActionSupport;@SuppressWarnings("serial")
public class ShowWords extends ActionSupport{
  private String name;
  private String words;
   public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}

public String getWords() {
return words;
} public void setWords(String words) {
this.words = words;
} public String execute()
{
if("".equals(name))
 {
return INPUT;
 }
else
 {
words = "欢迎您:" + name;
return SUCCESS;
 }
 }
}然后在test\WebRoot下编写了inputWords.jsp页面,关键代码如下:
<form name="myForm" action="showWords.action" method="post">
请输入您的姓名:<input name="name" type="text"/><br/>
<input type="submit" name="mySubmit" value="提交"/>
</form>
最后在test\WebRoot下编写了showWords.jsp页面,关键代码如下:
<body>
${words}
</body>我是完全按书上的例子来的 ,但是点击inputwords.jap上的按钮后出现如下错误;
HTTP Status 404 - /test/showWords.action--------------------------------------------------------------------------------type Status reportmessage /test/showWords.actiondescription The requested resource (/test/showWords.action) is not available.
--------------------------------------------------------------------------------Apache Tomcat/6.0.262、如何使用struts标签:
 网上有人说404的问题可能是struts2要使用自己的标签库,我试着直接在jsp中加入了如下代码:<s:form method="post" action="%{#request.contextPath}/orders">
   
  <table>
       
    <s:textfield name="clientName" label="Client"/>
        
    <s:textfield name="amount" label="Amount" />
        
      <tr>
           
        <td colspan="2">
                
          <s:submit />
            
        </td>
    
     </table>
    
  </s:form>
 
在myeclipse的设计中是可以看到这些标签的,也不报错,但生成页面里缺什么都没有,我也按照网上的办法添加了<@taglibprefix="s"uri="/struts-tags">或是在web.xml中添加如下代码:
<taglib> 
  <taglib-uri>/struts-tags</taglib-uri> 
  <taglib-location>/WEB-INF/struts-tags.tld</taglib-location> 
</taglib> 
页面报无法找到struts-tags的错,如果多次刷新错误可能会消失,但依然无法看到文本框和按钮;
请问以上两个问题的原因在哪?tomcat还需要什么配置吗?在网上有很多类似问题的解答,我基本上都试了,还有些解答说使用tomcat5.5问题可能被解决,但我没有试,初学中,请帮忙看看我可能出现的错在哪里或是漏了哪一步!!

解决方案 »

  1.   

    我使用的是tomcat6,启动过程如下:
    2012-2-17 0:20:53 org.apache.catalina.core.AprLifecycleListener init
    信息: Loaded APR based Apache Tomcat Native library 1.1.20.
    2012-2-17 0:20:53 org.apache.catalina.core.AprLifecycleListener init
    信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
    2012-2-17 0:20:53 org.apache.coyote.http11.Http11AprProtocol init
    信息: Initializing Coyote HTTP/1.1 on http-8181
    2012-2-17 0:20:53 org.apache.coyote.ajp.AjpAprProtocol init
    信息: Initializing Coyote AJP/1.3 on ajp-8009
    2012-2-17 0:20:53 org.apache.catalina.startup.Catalina load
    信息: Initialization processed in 496 ms
    2012-2-17 0:20:53 org.apache.catalina.core.StandardService start
    信息: Starting service Catalina
    2012-2-17 0:20:53 org.apache.catalina.core.StandardEngine start
    信息: Starting Servlet Engine: Apache Tomcat/6.0.26
    2012-2-17 0:20:53 org.apache.catalina.startup.HostConfig deployDescriptor
    信息: Deploying configuration descriptor host-manager.xml
    2012-2-17 0:20:53 org.apache.catalina.startup.HostConfig deployDescriptor
    信息: Deploying configuration descriptor manager.xml
    2012-2-17 0:20:54 org.apache.catalina.startup.HostConfig deployWAR
    信息: Deploying web application archive struts2-blank.war
    2012-2-17 0:20:54 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
    信息: Parsing configuration file [struts-default.xml]
    2012-2-17 0:20:54 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
    信息: Unable to locate configuration files of the name struts-plugin.xml, skipping
    2012-2-17 0:20:54 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
    信息: Parsing configuration file [struts-plugin.xml]
    2012-2-17 0:20:54 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
    信息: Parsing configuration file [struts.xml]
    2012-2-17 0:20:54 org.apache.catalina.startup.HostConfig deployWAR
    信息: Deploying web application archive struts2-rest-showcase.war
    2012-2-17 0:20:55 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
    信息: Parsing configuration file [struts-default.xml]
    2012-2-17 0:20:55 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
    信息: Parsing configuration file [struts-plugin.xml]
    2012-2-17 0:20:55 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
    信息: Parsing configuration file [struts.xml]
    2012-2-17 0:20:55 org.apache.catalina.startup.HostConfig deployDirectory
    信息: Deploying web application directory again
    2012-2-17 0:20:55 org.apache.catalina.startup.HostConfig deployDirectory
    信息: Deploying web application directory apps
    2012-2-17 0:20:55 org.apache.catalina.startup.HostConfig deployDirectory
    信息: Deploying web application directory docs
    2012-2-17 0:20:55 org.apache.catalina.startup.HostConfig deployDirectory
    信息: Deploying web application directory examples
    2012-2-17 0:20:56 org.apache.catalina.core.ApplicationContext log
    信息: ContextListener: contextInitialized()
    2012-2-17 0:20:56 org.apache.catalina.core.ApplicationContext log
    信息: SessionListener: contextInitialized()
    2012-2-17 0:20:56 org.apache.catalina.startup.HostConfig deployDirectory
    信息: Deploying web application directory ROOT
    2012-2-17 0:20:56 org.apache.catalina.startup.HostConfig deployDirectory
    信息: Deploying web application directory test
    2012-2-17 0:20:56 org.apache.coyote.http11.Http11AprProtocol start
    信息: Starting Coyote HTTP/1.1 on http-8181
    2012-2-17 0:20:56 org.apache.coyote.ajp.AjpAprProtocol start
    信息: Starting Coyote AJP/1.3 on ajp-8009
    2012-2-17 0:20:56 org.apache.catalina.startup.Catalina start
    信息: Server startup in 2599 ms
      

  2.   

    页面报无法找到struts-tags的错   就是你少导入jar包了呗
      

  3.   


    <!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.i18n.encoding" value="gb2312"/>
        <include file="struts-default.xml"/>
        <package name="action" namespace="/" extends="struts-default">
            <action name="showWords" class="action.ShowWords">
                <result name="success">showWords.jsp</result>
                <result name="input">inputWords.jsp</result>
            </action>
        </package>
    </struts>加上namespace
      

  4.   

    貌似struts2的标签已经都打包到jar包里了,而且是核心jar包
      

  5.   

    namespace我也加上试了下 还是不行
      

  6.   

    LZ,你访问的链接是:“/test/showWords.action”,但是你的配置是
    <package name="action" extends="struts-default">
            <action name="showWords" class="action.ShowWords">
                <result name="success">showWords.jsp</result>
                <result name="input">inputWords.jsp</result>
            </action>
        </package>
    ,你的namespace应该为:“/test”
      

  7.   

     在namespace中写成了“/test”还是不行 一样的404错
      

  8.   

    description The requested resource (/test/showWords.action) is not available.找不到请求的有效资源。你看看你的配置文件是不是写错了。class="action.ShowWords" 检查下路径
      

  9.   

    只看了你贴的报错信息,应该不是路径问题,可能是少什么jar包了
      

  10.   

    404是资源访问不到、一般是路径找不到或者不存在该访问的资源struts.xml里: 
      <package name="action" extends="struts-default" namespace="/">
            <action name="showWords" class="action.ShowWords">
                <result name="success">showWords.jsp</result>
                <result name="input">inputWords.jsp</result>
            </action>
        </package>前台表单
    <form name="myForm" action="/showWords.action" method="post">
    请输入您的姓名:<input name="name" type="text"/><br/>
    <input type="submit" name="mySubmit" value="提交"/>
    </form>你web.xml应该没什么问题 
    如果还有问题继续说明。
      

  11.   

    2、
    <@taglibprefix="s"uri="/struts-tags"> 这个需要放到jsp里最上面【调用之前、】
    而且你写错了吧?【<@taglib  prefix="s"  uri="/struts-tags"> 】 空格要明确啊、这个他会根据你写的路径去找、你看看你web-inf里面是否有这个tld文件
    <taglib> 
      <taglib-uri>/struts-tags</taglib-uri> 
      <taglib-location>/WEB-INF/struts-tags.tld</taglib-location> 
    </taglib>  你把这段去掉 直接就在jsp上面填写那句uri 然后在
    <s:debug></s:debug>在页面上写上、
    看能出来不、
    【楼主精神很执着啊、继续保持】
      

  12.   

    showWords.action.execute 这样试试,好久没写了strut2了!
      

  13.   

    返回值用小写的success试试,或者修改struts.xml中的 <result name="SUCCESS">showWords.jsp</result>
      

  14.   

    哈哈 感谢sd4000784的支持帮助 我看了好多的初学者都是这类问题,最终解决没也没有写出来!!
    1、我按照你的配置编写了struts.xml中的<package name="action" namespace="/" extends="struts-default">,在前台form中也写成了<form action="/showWords.action" method = "post">,现在执行后报的错为The requested resource (/showWords.action) is not available.路径问题?配置问题?类始终没有挂上。
    2、<%@ taglib prefix = "s" uri="/struts-tags"%>我现在是这样写的,就放在了jsp的最上面 ,还是找不到,我写成了uri="struts-tags",第一次没通过,但刷了几次,页面居然通过了,没报错,再生成时又报了“File "/WebRoot/struts-tags" not found”这样的错,然后我发现我的web-inf根本就没有这个文件,我又从struts2-core-2.2.3.jar中找到了struts-tags.tld文件,于是放入了test\webroot\web-inf下,结果还是不行,我感觉是路径的问题;
    3、还有个问题,myeclipse不能像eclipse那样启动tomcat吗?我发现只有停了tomcat的服务才可以用myeclipse的服务来启动tomcat。
      

  15.   

    你为什么不debug一下就知道哪里错误了
      

  16.   

    你看看他有没有进入public String execute()
        {
            if("".equals(name))
             {
                return INPUT;
             }
            else
             {
                words = "欢迎您:" + name;
                return SUCCESS;
             }
         }
    这个方法
      

  17.   


    1.在前台的提交页面中,<Form>中的 action路径是不需要斜线的..
        并且,你的 action必须在配置文件中设置好.关于这点,大致看了下楼朱最初的代码,都是有做,但一定不要出现问题...这类问题若出现,将非常麻烦.
    2.<%@ taglib prefix = "s" uri="/struts-tags"%>这样的写法根本没有问题,楼主不应改动...
        若这样写Myeclipse有报错,那就一定是导入的包有问题.楼主可以直接找人要一份齐全的包,然后全部重新导.
    3.至于楼主说的像Eclipse那样启动Tomcat,个人不是很清楚具体启动方式.但Myeclipse是有自带Tomcat的,这点与Eclipse非常大的差别.楼主说的停了Tomcat才能用Myeclipse的服务器启动,大概是因为你启动外部Tomcat导致端口被占用,所以内部的Tomcat才无法启动
      

  18.   

    public String execute()
        {
                     return SUCCESS;
     }
    这样写看行不?
      

  19.   

    <form name="myForm" action="showWords.action" method="post">
    请输入您的姓名:<input name="name" type="text"/><br/>
    <input type="submit" name="mySubmit" value="提交"/>
    </form>
    最后在test\WebRoot下编写了showWords.jsp页面,关键代码如下:
    <body>
    ${words}
    </body>name="myForm"  struts2没有form
      

  20.   

    <form name="myForm" action="showWords.action" method="post">
    改成
    <form action="showWords.action" method="post">
      另外开你的应用名是否正确 windows-prerences里面 是不是test
      

  21.   

     <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>
     第一你过滤器不知道对不?
    我用过org.apache.struts2.dispatcher.FilterDispatcher
    第二
    <url-pattern>/*</url-pattern>
    改成
    <url-pattern>/*.action</url-pattern>
      

  22.   

    <url-pattern>/*</url-pattern>
    这个不用改,没错
      

  23.   

    晕死,干嘛非得到非得把项目拷贝到Tomcat下面去,我这两天也出现这种错误,公司有个项目是用Eclipse做的,但是从上学起我就没用过Eclipse,只用MyEclipse和记事本,问题大条了,项目导入不了MyEclipse里面去,无奈只有直接在Tomcat下面运行,但总是报404,所以我直接在MyEclipse下面新建了一个工程,然后把代码和页面分别拷贝,然后用MyEclipse把项目添加到Tomcat下面,一次性成功,MyEclipse自带的Tomcat是非常好用的,所以你根本就不需要去自己配,而且自己配置出现了错误也不容易找到,之所以说了这么一大堆,嘿嘿,有没有高手帮我解决一下我这个问题呀,Eclipse如何才能导入到MyEclipse下面去啊,即使不导入到MyEclipse下面去,那求高手教教我如何配置到Tomcat下面去吧,以前上学的时候自己在Tomcat下面搞过,现在都忘了,QQ17784574,跪求啊,项目进行的很不顺利啊
      

  24.   

    server.xml中加入
     <Host>
        <Context docBase="E:\..\webRoot" path="/应用名" reloadable="true"/>
     </Host>
    直接启动tomcat就行
      

  25.   

    加个:namespace="/test" 试试,还有一点你的jsp导入了<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <base href="<%=basePath%>">这段代码没有?
      

  26.   

    第一个问题,路径有问题。怎么变成test了
      

  27.   

    看看conf\Catalina\localhost目录下有没生成xml文件,没有说明配置还有问题
      

  28.   

    应该是缺少了依赖的jar文件,可以查看tomcat的log找出具体问题。另外请从eclipse导出WAR文件到tomcat的webapps运行,如果没有问题了,那就行了
      

  29.   

    以下一些常见的struts2的配置异常
    1.
    严重: Exception starting filter struts2
    java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter2.
    严重: Dispatcher initialization failed
    java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    缺少包: javassist-3.11.0.GA.jar
    3.
    严重: Could not create JarEntryRevision for [jar:file:/D:/application/apache-tomcat-6.0.30/webapps/SSH1/WEB-INF/lib/struts2-core-2.3.4.jar]!
    java.lang.NoClassDefFoundError: org/apache/commons/io/FileUtils
    缺少包: commons-io-2.0.1.jar
    4.
    严重: Exception starting filter struts2
    java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
    缺少包: commons-lang3-3.1.jar