首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

Struts + tomcat 5出现在奇怪有关问题

2012-03-02 
Struts + tomcat 5出现在奇怪问题初学struts,在调第一个小应用时,首页可以正常显示,当点提交时出现如下错

Struts + tomcat 5出现在奇怪问题
初学struts,在调第一个小应用时,首页可以正常显示,当点提交时出现如下错误:
HTTP   Status   404   -   Servlet   action   is   not   available

type   Status   report

message   Servlet   action   is   not   available

description   The   requested   resource   (Servlet   action   is   not   available)   is   not   available.
----------------------------

以下为web.xml文件:
<?xml   version= "1.0 "   encoding= "ISO-8859-1 "   ?>

<web-app   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 "
        version= "2.4 ">

<icon> </icon>
<display-name> Struts   Base   Application </display-name>
<description> Struts   Base   Application </description>

<servlet>
<servlet-name> action </servlet-name>
<servlet-class> org.apache.struts.action.ActionServlet </servlet-class>
<init-param>
<param-name> config </param-name>
<param-value> /WEB-INF/struts-config.xml </param-value>
</init-param>
<load-on-startup> 1 </load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name> action </servlet-name>
<url-pattern> *.do </url-pattern>
</servlet-mapping>
</web-app>

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

以下为struts-config.xml:
<?xml   version= "1.0 "   encoding= "ISO-8859-1 "   ?>

<!DOCTYPE   struts-config   PUBLIC
                    "-//Apache   Software   Foundation//DTD   Struts   Configuration   1.1//EN "
                    "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd ">
                   
<struts-config>
<form-beans>
                                     
        <form-bean               name= "testForm "
                                          type= "org.apache.struts.validator.DynaValidatorForm ">
            <form-property   name= "name "   type= "java.lang.String "/>
                    <form-property   name= "comments "   type= "java.lang.String "/>
        </form-bean>

</form-beans>

<action-mappings>
<action   path= "/test "
        type= "com.wrox.begjsp.ch19.struts.TestAction "
                name= "testForm "


                validate= "true "
        input= "/index.jsp "
        scope= "request ">
        <forward   name= "success "   path= "/details.jsp "/>
        </action>        
</action-mappings>

<message-resources   parameter= "messages "   null= "false "/>

<plug-in   className= "org.apache.struts.validator.ValidatorPlugIn ">
        <set-property   property= "pathnames "  
                            value= "/WEB-INF/validator-rules.xml,  
                                          /WEB-INF/validation.xml "/>
</plug-in>

</struts-config>

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

以下是index.jsp代码:
<%@   taglib   uri= "/WEB-INF/struts-html.tld "   prefix= "html "   %>
<%@   taglib   uri= "/WEB-INF/struts-bean.tld "   prefix= "bean "   %>
<%@   taglib   uri= "/WEB-INF/struts-logic.tld "   prefix= "logic "   %>
<html>
<head>
<title> <bean:message   key= "form.title "/> </title>
</head>
<body>

<h1> <bean:message   key= "form.title "/> </h1>
<h3> what   will   showed   this   time? </h3>

<center>
<html:form   action= "/test "   method= "POST ">
<table   width= "350 "   border= "0 "   cellpadding= "3 "   cellspacing= "0 ">
<logic:messagesPresent   message= "false ">
<tr>
<td   colspan=2> <b> <bean:message   key= "errors.global "/> </b> </td>
</tr>
</logic:messagesPresent>
<logic:messagesPresent   property= "name ">
        <tr>
            <td   colspan=2> <html:errors   property= "name "/> </td>
        </tr>
    </logic:messagesPresent>    
<tr>
<td> <bean:message   key= "form.name.title "/> </td>
<td> <html:text   altKey= "form.name.title "   property= "name "   size= "30 "/> </td>
</tr>
<tr>
<td   valign= "top "> <bean:message   key= "form.comments.title "/> </td>
<td>
        <html:textarea   property= "comments "   cols= "30 "   rows= "8 "> </html:textarea>
</td>
</tr>
<tr>
<td> &nbsp; </td>
<td   align= "center "> <html:submit/> </td>
</tr>
</table>
</html:form>
</center>


</body>
</html>
-------------------------
index.jsp可以正常显示,在输入数据后,点 "提交 ",就会出现错误.浏览器地址显示为:
http://localhost:8080/struts-base/test.do(地址正确)

谢了先~~~~

[解决办法]
<html:form action= "/test " method= "POST ">
改成
<html:form action= "/test.do " method= "POST ">
试试
[解决办法]
404错误是没有找到指定的JSP文件~
[解决办法]
这个问题解决了吗?和我遇到的一样~有哪个大哥来指点一下
[解决办法]
看看你的struts的jar包是不是都在lib下面。
[解决办法]
给点建议,互相学习
1、看看你的action是不是继承而来,或者是不是继承错对象了;
2、JAR包是不是少了;
3、struts-config.xml是否放在WEB-INF目录下;
4、你的Form是直接指向了org.apache.struts.validator.DynaValidatorForm。
那你在jsp中元素肯定不会有GETTER方法,建议从DynaValidatorForm继承出一个新类包含你表单中需要的元素;

热点排行