[英]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.