英文:
Why am I not able to print values using EL in JSP?
问题
我正在使用IntelliJ Ultimate尝试基本的JSP和Servlet示例。
我有一个简单的 **Person类**:
public class Person implements Serializable {
public String name = "Alexa";
public String getName() {
return name;
}
}
以及一个 **Servlet**:
public class GenericServlet extends HttpServlet {
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Person person = new Person();
RequestDispatcher rd = request.getRequestDispatcher("display.jsp");
request.setAttribute("person", person);
rd.forward(request, response);
System.out.println("Passed to display jsp");
}
}
我只是想使用 **JSP** 打印人的姓名:
<jsp:useBean id="person" scope="request" class="com.sample.Person"/>
......
<h2>人的姓名是: <jsp:getProperty name="person" property="name"/></h2>
<h2>人的姓名是: ${person.name}</h2>
我能够使用第一个h2标签打印,但不能使用第二个,即使我可以在JSP中自动完成person.name。
寻找缺失的部分。谢谢!
英文:
I am using Intellij Ultimate to try out basic examples of JSP and Sevlets.
I have a simple Person class:
public class Person implements Serializable {
public String name = "Alexa";
public String getName() {
return name;
}
}
And a Servlet:
public class GenericServlet extends HttpServlet {
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Person person = new Person();
RequestDispatcher rd = request.getRequestDispatcher("display.jsp");
request.setAttribute("person", person);
rd.forward(request, response);
System.out.println("Passed to display jsp");
}
}
And I am simply trying to print the person name using JSP:
<jsp:useBean id="person" scope="request" class="com.sample.Person"/>
......
<h2>Name of person is: <jsp:getProperty name="person" property="name"/></h2>
<h2>Name of person is: ${person.name}</h2>
I am able to print using first h2 tag but not with second, even when I am able to auto-complete person.name in JSP.
Looking for missing bits here. Thanks!
专注分享java语言的经验与见解,让所有开发者获益!
评论