0

Java クラス DetailsForm で planValue の値を設定しています。jsp でそのプロパティ値を取得する必要があります。どうすれば入手できますか?ここのjspでは、javaと同じ名前をplanValueと同じに使用しています。

ありがとう

4

1 に答える 1

0

次のサーブレット コードのようなものを使用します。

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 メソッドが必要です。

于 2012-07-27T06:21:22.093 に答える