从 JSP 调用 Java 方法时出现内部服务器错误
Internal Server error while calling an Java method from JSP
这是我的JSP
extra.jsp
:
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<html>
<head>
</head>
<body>
<h1><bean:write name="HelloWorldForm" property="message">
</h1>
</body>
</html>
这个表单Bean
HelloWorldForm.java
:
package com.redhat.rhn.frontend.action.common;
import org.apache.struts.action.ActionForm;
public class HelloWorldForm extends ActionForm{
String message="HelloWorld!";
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
这是行动
HelloWorldAction.java
:
package com.redhat.rhn.frontend.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.redhat.rhn.frontend.action.common.HelloWorldForm;
public class HelloWorldAction extends Action{
public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws Exception {
HelloWorldForm HelloWorldForm = (HelloWorldForm) form;
HelloWorldForm.setMessage("Hello World! Struts");
return mapping.findForward("success");
}
}
我在 struts-config 文件中添加了以下代码
struts-config.xml
:
<form-bean name="HelloWorldForm"
type="com.redhat.rhn.frontend.common.HelloWorldForm">
</form-bean>
<action path="/extra"
scope="request"
name="HelloWorldForm"
type="com.redhat.rhn.frontend.action.HelloWorldAction">
<forward name="success" path="/WEB-INF/pages/extra.jsp" />
</action>
当我尝试从浏览器访问 extra.jsp 时出现内部服务器错误
打印 hello world 的目的是了解如何从 jsp
调用 java 方法
错误代码500是jasper编译器在编译JSP页面时产生的错误
标签
<bean:write name="HelloWorldForm" property="message">
未关闭,编译器将导致错误,状态代码为 500
这是我的JSP
extra.jsp
:
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<html>
<head>
</head>
<body>
<h1><bean:write name="HelloWorldForm" property="message">
</h1>
</body>
</html>
这个表单Bean
HelloWorldForm.java
:
package com.redhat.rhn.frontend.action.common;
import org.apache.struts.action.ActionForm;
public class HelloWorldForm extends ActionForm{
String message="HelloWorld!";
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
这是行动
HelloWorldAction.java
:
package com.redhat.rhn.frontend.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.redhat.rhn.frontend.action.common.HelloWorldForm;
public class HelloWorldAction extends Action{
public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws Exception {
HelloWorldForm HelloWorldForm = (HelloWorldForm) form;
HelloWorldForm.setMessage("Hello World! Struts");
return mapping.findForward("success");
}
}
我在 struts-config 文件中添加了以下代码
struts-config.xml
:
<form-bean name="HelloWorldForm"
type="com.redhat.rhn.frontend.common.HelloWorldForm">
</form-bean>
<action path="/extra"
scope="request"
name="HelloWorldForm"
type="com.redhat.rhn.frontend.action.HelloWorldAction">
<forward name="success" path="/WEB-INF/pages/extra.jsp" />
</action>
当我尝试从浏览器访问 extra.jsp 时出现内部服务器错误 打印 hello world 的目的是了解如何从 jsp
调用 java 方法错误代码500是jasper编译器在编译JSP页面时产生的错误
标签
<bean:write name="HelloWorldForm" property="message">
未关闭,编译器将导致错误,状态代码为 500