我在我的 java 类 DetailsForm 中设置 planValue 的值。我需要在 jsp 中获取该属性值。我将如何得到它?我在 jsp 中使用与 java 中的 planValue 相同的名称。
谢谢
使用类似这样的 Servlet 代码:
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
performTask(request, response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
performTask(request, response);
}
public void performTask(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException { //create your object
DetailsForm detailsForm = new DetailsForm();
//set planValue
detailsForm.setPlanValue("some plan value");
//set your object as attribute and use forward
request.setAttribute("detailsForm", detailsForm);
//relative path to your JSP
request.getRequestDispatcher("/pages/some.jsp").forward(request,
response);
}
还有你的 some.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<html>
<head>
<title>
Some JSP
</title>
<head>
<body>
${detailsForm.plainValue}
</body>
</html>
并且您需要在 DetailsForm 类中为 plainValue 提供 getter 方法。