我实现了一个很简单的struts程序,但是屡屡出现问题,解决了一个又一个,都快神经了!各位大虾给帮忙看看!
这里是我的提示错误!
type Status reportmessage Servlet action is not availabledescription The requested resource (Servlet action is not available) is not available.
我的文件如下:
------------struts-config文件----------------
<?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>
    <!-- ========== 数据源定义 =============================== -->
    <data-sources />
    <!-- ========== Form Bean定义 ================================== -->
    <form-beans>
        <form-bean name="loginForm" type="org.apache.my.form.LoginForm"> 
</form-bean>
    </form-beans>
    
    <!-- ========== 全局异常 ============================== -->
    <global-exceptions />
    
    <!-- ========== 全局Forward=============================== -->
    <global-forwards />
    
    <!-- ========== Action Mapping(操作映射) =============================== -->
    <action-mappings>
<action path="/login" type="org.apache.my.action.LoginAction" 
  name="loginForm" scope="request" input="/login.jsp">
  <forward name="success" path="/main.jsp" />
  <forward name="failed"  path="/error.jsp" />
</action> 
</action-mappings>
    
    <!-- ========== Controller Configuration ================================ -->
    <controller />
    
    <!-- ========== Message Resources Definitions ============================ -->
    <message-resources parameter="org.apache.my.ApplicationResources"/>    <!-- ========== Plug Ins Configuration ================================= -->
<plug-in className=""/>
</struts-config>============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"> <display-name>LoginExample</display-name>    <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>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <init-param>
            <param-name>detail</param-name>
            <param-value>0</param-value>
        </init-param>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
        </init-param>
        <load-on-startup>0</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>  <taglib>
    <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
  </taglib>  <taglib>
    <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
  </taglib>  <taglib>
    <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
  </taglib>  <taglib>
    <taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
  </taglib>  <taglib>
    <taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
  </taglib></web-app>
-----------login.jsp文件<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<html:html>
   <head>
       <title>  Struts  主页</title>
   </head>
   <body>
      <h3>正确的登录用户名和密码是:hh</h3>
      <P>
         <html:form action="/login.do" focus="username">
             <table>
                 <tr>
                     <td>用户名:</td>
                     <td><html:text property="username"/></td>
                 </tr>
                 <tr>
                     <td>密码:</td>
                     <td><html:password property="password" redisplay="false"/></td>
                 </tr>
                 <tr>
                     <td colspan=2 align=right>
                          <html:submit value="确定 "/>
                     </td>
                </tr>
             </table>
         </html:form>
 </P>
    </body>
</html:html>
------------main.jsp---------
<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<html:html locale="true">
   <head>
       <title>成功了</title>
       <html:base/>
   </head>
    <body>
        <P>注册成功!</P>
<P><BR>
<BR>
<A href="login.jsp">再试一次</A>?
</P>
    </body>
</html:html>
------------error.jsp-----------------
<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html:html locale="true">
   <head>
       <title>出错了</title>
       <html:base/>
   </head>
    <body>
<P>登陆失败!请检查用户名和密码是否正确!</P>
<P><BR>
<BR>
<A href="login.jsp">再试一次</A>?
</P> 
    </body>
</html:html>

解决方案 »

  1.   

    ============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">应该是这里出现问题了吧,应该这样写
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
      

  2.   

    你肯定是用eclipse和myeclipse写的吧
      

  3.   

    如果你觉得程序没有问题,那么你把struts-config.xml中的关于数据源的配置先去掉,然后试,看如何?我以前也遇到过类似的问题,去掉数据源配置就正常运行。加上,就出错,哪怕你不调用,因为在启动的时候就出错了!
      

  4.   

    我现在启动的时候是正常的,但是就是在调用login.jsp时出错了,楼上的方法我也试过,不行啊