如何从java类中获取值并将其映射到jsp中的select语句?

时间:2012-07-27 03:42:03

标签: java jsp struts

我在我的java类 - DetailsForm中设置了for- planValue的值。我需要在jsp中获取该属性值。我怎么得到它?我使用的名称与planValue相同,如jsp中的java。

                                                                                           

由于

1 个答案:

答案 0 :(得分:0)

使用类似这样的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方法。