Java 为什么不从表单值创建请求范围的bean?

Java 为什么不从表单值创建请求范围的bean?,java,jsp,scope,request,javabeans,Java,Jsp,Scope,Request,Javabeans,我创建了这样一个JSP文件: <jsp:useBean id="ucz" class="pl.lekcja.beany.beany.Uczen" scope="request"> <jsp:setProperty name="ucz" property="*"/> </jsp:useBean> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html

我创建了这样一个JSP文件:

<jsp:useBean id="ucz" class="pl.lekcja.beany.beany.Uczen" scope="request">
    <jsp:setProperty name="ucz" property="*"/> 
</jsp:useBean>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Podaj dane ucznia:</h1>

        <form method="POST" action="Ocen">
            <table>
                <tr>
                    <td>Imie:</td>
                    <td><input type="text" name="imie" /></td>
                </tr>
                <tr>
                    <td>Nazwisko:</td>
                    <td><input type="text" name="nazwisko" /></td>
                </tr>
                <tr>
                    <td>Punkty:</td>
                    <td><input type="text" name="punkty" /></td>
                </tr>
                <tr>
                    <td colspan="2"><input type="submit" value="Oceń" /></td>
                </tr>
            </table>
        </form>
    </body>
</html>
和Servlet:

public class Ocen extends HttpServlet {

    private static final int PROG_PUNKTOWY = 50;

    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Uczen uczen = (Uczen)request.getAttribute("ucz");
        System.out.println(uczen); // <---- here prints null, always, there's no "uczen" object in attributes
        String czyZdal = "nie ";

        if (uczen.getPunkty() >= PROG_PUNKTOWY) {
            czyZdal = " ";
        }

        request.setAttribute("czyZdal", czyZdal);
        request.getRequestDispatcher("/WEB-INF/wynik.jsp").forward(request, response);
    }
}
公共类Ocen扩展了HttpServlet{ 私有静态最终int PROG_PUNKTOWY=50; 受保护的void processRequest(HttpServletRequest请求,HttpServletResponse响应)引发ServletException,IOException{ Uczen Uczen=(Uczen)request.getAttribute(“ucz”);
System.out.println(uczen);//您将请求发布到
Ocen
servlet。当servlet被执行时,JSP还没有被执行,因此
JSP:useBean
还没有被执行,所以bean还没有在请求中


jsp:useBean
不应该再使用了。请求参数应该在您的控制器servlet中读取,而不是在jsp中读取。您应该使用一个MVC框架,如Spring MVC或Stripes,它会自动将请求参数转换为表单bean,并将此表单bean传递给一个操作。

感谢您澄清这个问题嗯,我看到有两个不同的请求,由两个不同的东西发出,但我认为这些元素之间会有某种合作。我喜欢Spring框架,但出于我自己的需要,我不得不回去,只在servlet/jsp级别上执行。
public class Ocen extends HttpServlet {

    private static final int PROG_PUNKTOWY = 50;

    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Uczen uczen = (Uczen)request.getAttribute("ucz");
        System.out.println(uczen); // <---- here prints null, always, there's no "uczen" object in attributes
        String czyZdal = "nie ";

        if (uczen.getPunkty() >= PROG_PUNKTOWY) {
            czyZdal = " ";
        }

        request.setAttribute("czyZdal", czyZdal);
        request.getRequestDispatcher("/WEB-INF/wynik.jsp").forward(request, response);
    }
}