【发布时间】:2011-02-03 17:26:17
【问题描述】:
我正在尝试从由 servlet 设置和调度的 jsp 页面访问会话属性,但我收到错误消息“jsp:attribute must be the subelement of a standard or custom action”。可能出了什么问题,我是否错误地访问它?以下是代码sn-p。
小服务程序:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
session.setAttribute("Questions", getQuestion());
System.out.println(session.getAttribute("Questions"));
RequestDispatcher req = request.getRequestDispatcher("DisplayQuestions.jsp");
req.forward(request, response);
}
private QuestionBookDAO getQuestion(){
QuestionBookDAO q = new QuestionBookDAO();
q.setQuestion("First Question");
q.setQuestionPaperID(100210);
q.setSubTopic("Java");
q.setTopic("Threads");
return q;
}
我能够成功设置会话属性。但是当我尝试在我的 jsp 文件(如下)中访问相同的内容时,我遇到了运行时错误
<jsp:useBean id="Questions" type="com.cet.evaluation.QuestionBook" scope="session">
<jsp:getProperty property="Questions" name="questionPaperID"/>
<jsp:getProperty property="Questions" name="question"/>
</jsp:useBean>
bean QuestionBook 包含两个私有变量 questionPaperID 和 question 我在 Tomcat 上运行应用程序,下面是抛出的错误。
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /DisplayQuestions.jsp(15,11) jsp:attribute must be the subelement of a standard or custom action
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88)
org.apache.jasper.compiler.Parser.parseStandardAction(Parser.java:1160)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1461)
org.apache.jasper.compiler.Parser.parseBody(Parser.java:1670)
org.apache.jasper.compiler.Parser.parseOptionalBody(Parser.java:1020)
....
【问题讨论】: