[英]How to get value from java class and map it to select statement in jsp?
我在我的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方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.