在JSP中无法正确读取JSTL
美好的一天!
我尝试在Java中使用JSTL,但出现错误:
I tried using JSTL in java but there's an error:
exception
javax.servlet.ServletException: java.lang.InstantiationException: class session.Item : java.lang.InstantiationException: session.Item
root cause
java.lang.InstantiationException: class session.Item : java.lang.InstantiationException: session.Item
我的代码如下:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>DISPLAY ITEM</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<jsp:useBean id="invenItem" class="session.Item" scope="request"/>
<c:choose>
<c:when test="${invenItem != null}">
<h1>Inventory Item Details: JSP Tester</h1>
Stock ID : <jsp:getProperty name="invenItem" property="stockID" /><br/>
Name : <jsp:getProperty name="invenItem" property="itemName" /><br/>
Unit Price: <jsp:getProperty name="invenItem" property="unitPrice" /><br/>
On Stock : <jsp:getProperty name="invenItem" property="onStock" />
<h1> Inventory Item Details Tester: EL Method </h1>
Stock ID : ${invenItem.stockID} <br/>
Name : ${invenItem.itemName}<br/>
Unit Price: ${invenItem.unitPrice}<br/>
On Stock : ${invenItem.onStock}
</c:when>
<c:otherwise>
<%@ include file ="DataForm.html" %><br>
Item not existing!<br>
<%@ include file ="ItemEntry.html" %>
</c:otherwise>
</c:choose>
</body>
</html>
我已经阅读了 JLPT ,并按照那里的所有说明进行操作.请帮忙.谢谢.
I've read this JLPT already and followed all the instructions there. Please help. Thank you.
编辑...
我按照建议解决了该错误,但是JSTL(如果不是其他逻辑)仍然无法正常工作.请帮助!!!!
I resolved the error as suggested, but still the JSTL (if else logic) is not working. HELP PLEASE!!!!
如果invenItem
作为请求属性已经存在,则无需使用<jsp:useBean>
来检索它,您可以直接在<jsp:useBean>
中使用它.您的JSP,因此只需完全删除<useBean>
行.
If invenItem
already exists as a request attribute, then you don't need to use <jsp:useBean>
to retrieve it, you can just use it directly in your JSP, so just remove the <useBean>
line completely.
如果invenItem
不存在作为请求属性,则<jsp:useBean>
将为您创建一个,但是您在class
属性中输入的内容必须完全合格具有公共默认构造函数的类的名称,否则您将看到所看到的异常.
If invenItem
doesn't already exist as a request attribute, then <jsp:useBean>
will create one for you, but whatever you put in the class
attribute must be the fully-qualified name of a class with a public, default constructor, else you'll get the exception you saw.