如果这是一个超级简单的问题,我对 Java 和 JSTL 真的很陌生,很抱歉。我试图举一个我在网上找到的例子并让它工作,但我似乎遇到了问题。假设发生的所有事情都是您创建一个 java bean 并从 java bean 访问属性。但相反,我在 JSTL jsp:useBean id="students" class="com.beans.Students"中调用类的行上出现空指针异常。这是java类:
package com.beans;
public class Students implements java.io.Serializable
{
private String firstName = null;
private int age = 0;
public Students() {
}
public String getFirstName(){
return firstName;
}
public int getAge(){
return age;
}
public void setFirstName(String firstName){
this.firstName = firstName;
}
public void setAge(Integer age){
this.age = age;
}
}
我试图在其中访问 Java bean 的 JSTL:
<jsp:useBean id="students"
class="com.beans.Students">
<jsp:setProperty name="students" property="firstName"
value="Zara"/>
<jsp:setProperty name="students" property="age"
value="10"/>
</jsp:useBean>
<p>Student First Name:
<jsp:getProperty name="students" property="firstName"/>
</p>
<p>Student Age:
<jsp:getProperty name="students" property="age"/>
</p>
堆栈跟踪:
Caused by: org.apache.sling.api.SlingException: An exception occurred processing JSP page /students.jsp at line 18
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspExceptionInternal(JspServletWrapper.java:574)
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:499)
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
at org.apache.sling.scripting.jsp.JspServletWrapperAdapter.service(JspServletWrapperAdapter.java:59)
at org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.eval(JspScriptEngineFactory.java:453)
at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:358)
... 174 more
Caused by: java.lang.NullPointerException
at org.apache.sling.scripting.jsp.jasper.runtime.JspRuntimeLibrary.internalIntrospecthelper(JspRuntimeLibrary.java:322)
at org.apache.sling.scripting.jsp.jasper.runtime.JspRuntimeLibrary.introspecthelper(JspRuntimeLibrary.java:308)
at org.apache.jsp.students_002d_jsp._jspServ
任何帮助是极大的赞赏!