0

我被这个错误困住了 n 无法找到我出错的地方

这是代码..请使用 myelipse,struts1.2 浏览它

struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts      Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">

<struts-config>
<data-sources />
<form-beans />
<global-exceptions />
<global-forwards />
<action-mappings>
        <action path="/SwitchAction"  type="org.apache.struts.actions.SwitchAction"/>
 </action-mappings>
<message-resources parameter="com.yourcompany.struts.ApplicationResources" />
</struts-config>

struts-config-Admin.xml

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">

   <struts-config>
    <data-sources />
    <form-beans>
        <form-bean name="adminLoginForm" type="Admin.Form.AdminLoginForm" />
        <form-bean name="adminUserCreationForm" type="Admin.Form.AdminUserCreationForm" />


    </form-beans>

    <global-exceptions />
    <global-forwards />
    <action-mappings>
        <action attribute="AdminLoginForm" input="/AdminModule/AdminLogin.jsp"
            name="adminLoginForm" path="/AdminLogin" scope="request"
            type="Admin.Action.AdminLoginAction">
            <set-property property="cancellable" value="true" />
            <forward name="failure" path="/AdminErrorPage.jsp" />
            <forward name="success" path="/AdminHomePage.jsp" />
        </action>
        <action attribute="adminUserCreationForm" input="/AdminModule/AdminUserCreation.jsp"
            name="adminUserCreationForm" path="/AdminUserCreation" scope="request"
            type="Admin.Action.AdminUserCreationAction">
            <set-property property="cancellable" value="true" />
            <forward name="failure" path="/AdminModule/AdminErrorPage.jsp" />
            <forward name="success" path="/AdminModule/AdminSuccessPage.jsp" />
        </action>
    </action-mappings>
</struts-config>

AdminUserCreationAction.java

    <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>

<html>
    <head>
        <base href="<%=basePath%>"    
    </head>

    <body>
        User Creation Page
        <html:form action="/AdminUserCreation">
            AdminName : <html:text property="username"/><html:errors property="username"/><br/>
            Password : <html:password property="password"/><html:errors property="password"/><br/>
            <html:submit/>
        </html:form>
    </body>
</html>

AdminUserCreationForm.java

package Admin.Form;

import org.apache.struts.action.ActionForm;

public class AdminUserCreationForm extends ActionForm {

    private String username;
    private String password;
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
}

AdminUserCreation.jsp

    <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%> 
    </head>
    <body>
        User Creation Page
        <html:form action="/AdminUserCreation">
            AdminName : <html:text property="username"/><html:errors property="username"/><br/>
            Password : <html:password property="password"/><html:errors property="password"/><br/>
            <html:submit/>
        </html:form>
    </body>
</html>

我进入浏览器时出错

 type Exception report

     message 

     description The server encountered an internal error () that prevented it from fulfilling this request.

     exception 

     org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot retrieve mapping for action /AdminUserCreation
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:541)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause 

     javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot retrieve mapping for action /AdminUserCreation
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
    org.apache.jsp.AdminModule.AdminUserCreation_jsp._jspService(AdminUserCreation_jsp.java:114)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause 

     javax.servlet.jsp.JspException: Cannot retrieve mapping for action /AdminUserCreation
    org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:759)
    org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:443)
    org.apache.jsp.AdminModule.AdminUserCreation_jsp._jspx_meth_html_005fform_005f0(AdminUserCreation_jsp.java:131)
    org.apache.jsp.AdminModule.AdminUserCreation_jsp._jspService(AdminUserCreation_jsp.java:104)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


     note The full stack trace of the root cause is available in the Apache Tomcat/6.0.13 logs.

msg im gettng 在控制台中

 Servlet.service() for servlet jsp threw exception
 javax.servlet.jsp.JspException: Cannot retrieve mapping for action /AdminUserCreation
 at org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:759)
    at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:443)
    at org.apache.jsp.AdminModule.AdminUserCreation_jsp._jspx_meth_html_005fform_005f0(AdminUserCreation_jsp.java:131)
    at org.apache.jsp.AdminModule.AdminUserCreation_jsp._jspService(AdminUserCreation_jsp.java:104)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)
4

1 回答 1

0

这里有些奇怪(尽管它可能不是问题的唯一原因):

在你的 struts 配置文件中,你已经定义了

<action attribute="adminUserCreationForm" .....
            type="Admin.Action.AdminUserCreationAction">

这意味着应该在 Admin.Action 包下找到类 AdminUserCreationAction。

但是,您的 AdminUserCreationAction 类在 Admin.Form 包下声明:

package Admin.Form;
public class AdminUserCreationForm ...

请尝试在这两种情况下使用相同的包名。

于 2014-11-20T17:35:21.800 回答