gpt4 book ai didi

java - etat HTTP 500 - javax.servlet.ServletException : javax. servlet.jsp.JspException:找不到 ActionMappings 或 ActionFormBeans 集合

转载 作者:行者123 更新时间:2023-12-01 11:42:36 25 4
gpt4 key购买 nike

我是 Struts 新手,我遵循有关如何创建 Struts Web 应用程序的教程。这是我创建的文件。

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Mon application Struts de tests</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>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>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

Struts-config.xml

  <?xml version="1.0" encoding="UTF-8"?>
<!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="HelloWorldForm" type="com.hello.HelloWorldFrom" />
<form-bean name="LoginForm" type="com.test.LoginForm.LoginForm"/>
</form-beans>
<action-mappings type="org.apache.struts.action.ActionMapping">
<action path="/helloWorld" type="com.hello" name="HelloWorldForm">
<forward name="success" path="/HelloWorld.jsp" />
</action>
<action path="login" parameter="" input="/index.jsp" scope="request"
name="loginForm" type="com.test.controller.LoginAction">
<forward name="succes" path="/accueil.jsp" redirect="false" />
<forward name="echec" path="/index.jsp" redirect="false" />
</action>
</action-mappings>

index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page language="java" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html:html locale="true">
<head>
<title>authentication</title>
<html:base/>
</head>
<body bgcolor="white">
<html:form action="login" focus="nameUserr">
<table border="0" align="center">
<tr>
<td align="right">
User:
</td>
<td align="left">
<html:text property="nameUserr" size="20" maxlength="20"/>
</td>
</tr>
<tr>
<td align="right">
Password :
</td>
<td align="left">
<html:password property="psdUser" size="20" maxlength="20"
redisplay="false"/>
</td>
</tr>
<tr>
<td align="right">
<html:submit property="submit" value="Submit"/>
</td>
<td align="left">
<html:reset/>
</td>
</tr>
</table>
</html:form>

LoginAction.java

package com.test.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.*;
import com.test.LoginForm.LoginForm;
public class LoginAction extends Action{

public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest req,
HttpServletResponse res) throws Exception {

String result = null;
String nomUtilisateur = ((LoginForm) form).getNameUser();
String mdpUtilisateur = ((LoginForm) form).getPsdUser();

if (nameUser.equals("xyz") && psdUser.equals("xyz")) {
result = "succes";
} else {
result = "failure";
}

return mapping.findForward(result);
}
}

LoginForm.java

package com.test.LoginForm;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
public class LoginForm extends ActionForm{
String nameUser;

String psdUser;

public String getpsdUser() {
return psdUser;
}

public void setpsdUser(String psdUser) {
this.psdUser= psdUser;
}

public String getnameUser() {
return nameUser;
}

public void setnameUser(String nameUser) {
this.nameUser= nameUser;
}

public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
return errors;
}

public void reset(ActionMapping mapping, HttpServletRequest request) {
this.psdUser= null;
this.nameUser= null;
}

}

但是运行时出现以下错误

Etat HTTP 500 - javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection

编辑:完整的堆栈跟踪

Report type Exception 

Message javax.servlet.ServletException: javax.servlet.jsp.JspException: Can not find ActionMappings gold ActionFormBeans collection
description The server encountered an internal error that prevented it from fulfilling the request.

exception
org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: Can not find ActionMappings gold ActionFormBeans collection
org.apache.jasper.servlet.JspServletWrapper.handleJspException (JspServletWrapper.java:549)
org.apache.jasper.servlet.JspServletWrapper.service (JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile (JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service (JspServlet.java:339)
javax.servlet.http.HttpServlet.service (HttpServlet.java:727)

Parent cause

javax.servlet.ServletException: javax.servlet.jsp.JspException: Can not find ActionMappings gold ActionFormBeans collection
org.apache.jasper.runtime.PageContextImpl.doHandlePageException (PageContextImpl.java:916)
org.apache.jasper.runtime.PageContextImpl.handlePageException (PageContextImpl.java:845)
org.apache.jsp.index_jsp._jspService (index_jsp.java:112)
org.apache.jasper.runtime.HttpJspBase.service (HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service (HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service (JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile (JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service (JspServlet.java:339)
javax.servlet.http.HttpServlet.service (HttpServlet.java:727)

Parent cause

javax.servlet.jsp.JspException: Can not find ActionMappings gold ActionFormBeans collection
org.apache.struts.taglib.html.FormTag.lookup (FormTag.java:798)
org.apache.struts.taglib.html.FormTag.doStartTag (FormTag.java:506)
org.apache.jsp.index_jsp._jspx_meth_html_005fform_005f0 (index_jsp.java:189)
org.apache.jsp.index_jsp._jspx_meth_html_005fhtml_005f0 (index_jsp.java:143)
org.apache.jsp.index_jsp._jspService (index_jsp.java:99)
org.apache.jasper.runtime.HttpJspBase.service (HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service (HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service (JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile (JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service (JspServlet.java:339)
javax.servlet.http.HttpServlet.service (HttpServlet.java:727)
Note The complete trace of the mother cause of this error is available in the log files for Apache Tomcat / 7.0.59.

我用谷歌搜索并尝试了所有建议的解决方案,但错误仍然存​​在。任何想法请。

P.S:我使用 Struts 1.1

最佳答案

struts-config.xml在你的文件中以 </action-mappings> 结尾而不是<struts-config>

此外,每个文件中都存在许多错误。所以看来您没有尝试验证您的代码是否正确。

1) 在 web.xml文件

DTD 声明有问题,应该是这样的:

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

2) 在 struts-config.xml文件:

您已将表单 Bean 名称声明为 LoginFormaction 中所示您将其用作 loginForm

也没有forward显示当操作类返回 failure 时您想要执行的操作的声明.

所以代码应该是这样的:

   <action path="/login" parameter="" input="/index.jsp" scope="request"
name="LoginForm" type="com.test.controller.LoginAction">
<forward name="succes" path="/accueil.jsp" redirect="false" />
<forward name="echec" path="/index.jsp" redirect="false" />
<forward name="failure" path="/loginFailed.jsp" redirect="false" />
</action>

3) 在 index.jsp您有多个问题:

a) taglib 声明应如下所示(对于 Struts 1.3.10):

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="logic" %>

b) struts html 自定义标签没有任何名为 locale 的属性index.jsp 还显示您没有关闭 struts html 标记。

检查一下:

<html:html>
......
</html:html>

c) 属性声明:

<html:text property="nameUserr" size="20" maxlength="20"/>

表示表单 bean 有一个名为 nameUserr 的属性但是LoginForm属性声明为 nameUser所以将jsp文件中的代码更改为

<html:text property="nameUser" size="20" maxlength="20"/>

4) LoginForm bean 有错误的 getter 和 setter 方法。它们应该是这样的:

public String getNameUser() {
return nameUser;
}

public void setNameUser(String nameUser) {
this.nameUser = nameUser;
}

public String getPsdUser() {
return psdUser;
}

public void setPsdUser(String psdUser) {
this.psdUser = psdUser;
}

5) 终于在 LoginAction你的action类比较不正确,应该是:

        String nomUtilisateur = ((LoginForm) form).getNameUser();
String mdpUtilisateur = ((LoginForm) form).getPsdUser();

if (nomUtilisateur.equals("xyz") && mdpUtilisateur.equals("xyz")) {
result = "succes";
} else {
result = "failure";
}

关于java - etat HTTP 500 - javax.servlet.ServletException : javax. servlet.jsp.JspException:找不到 ActionMappings 或 ActionFormBeans 集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29407132/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com