我一直在做一个 JSP/struts 项目,现在我只是想在开始实际项目之前建立基本的第一页并开始工作,但我对 struts 很陌生,在 MyEclipse 中部署我的页面之后,尝试通过浏览器访问本地主机页面时,我不断收到错误消息。我得到的错误是:
HTTP Status 500 -
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 definition for form bean userLoginForm
它从那里继续,但这是基本信息。
初始 JSP 页面的代码是
<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<html>
<head>
<title>JSP for UserLoginForm form</title>
</head>
<body>
<html:form action="/userLogin">
userName : <html:text property="userName"/><html:errors property="userName"/><br/>
enter : <html:text property="enter"/><html:errors property="enter"/> <br/>
server : <html:text property="server"/><html:errors property="server"/><br/>
password : <html:text property="password"/><html:errors property="password"/><br/>
<html:submit/><html:cancel/>
</html:form>
</body>
</html>
使用的 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>
<data-sources />
<form-beans >
<form-bean name="UserLoginForm" type="strutsPackage.struts.form.UserLoginForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings >
<action
attribute="userLoginForm"
input="/login.jsp"
name="userLoginForm"
path="/userLogin"
scope="request"
type="strutsPackage.struts.action.UserLoginAction">
<forward name="failure" path="/login.jsp" />
<forward name="success" path="/login.jsp" />
</action>
</action-mappings>
<message-resources parameter="strutsPackage.struts.ApplicationResources" />
</struts-config>
操作页面是:
package strutsPackage.struts.action;
import javax.servlet.http.HttpServletRequest;
/**
* MyEclipse Struts
* Creation date: 04-18-2013
*
* XDoclet definition:
* @struts.action path="/userLogin" name="userLoginForm" input="/login.jsp" scope="request" validate="true"
* @struts.action-forward name="failure" path="/login.jsp"
* @struts.action-forward name="success" path="/login.jsp"
*/
public class UserLoginAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
UserLoginForm userLoginForm = (UserLoginForm) form;
if(userLoginForm.getUserName().equals("myeclipse") && userLoginForm.getPassword().equals("myeclipse"))
{
request.setAttribute("userName", userLoginForm.getUserName());
return mapping.findForward("success");
}
return mapping.findForward("failure");
}
}
每隔一段时间我就会得到一个不同的错误页面,上面写着
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /login.jsp at line 10
7: <title>JSP for UserLoginForm form</title>
8: </head>
9: <body>
10: <html:form action="/userLogin">
11: userName : <html:text property="userName"/><html:errors property="userName"/><br/>
12: enter : <html:text property="enter"/><html:errors property="enter"/><br/>
13: server : <html:text property="server"/><html:errors property="server"/><br/>
这些错误似乎没有明显的原因互换,但真正让我困惑的是我昨天让页面显示正常,不再触摸它,今天当我试图打开它时,我得到了第一个错误页面。我已经尝试重新部署该网站,但我仍然得到同样的结果。
所以我不知道这是否是我的代码或我的 Tomcat 版本的问题,或者我的代码是否有问题。
任何帮助将不胜感激。