servlet请求setAttibute和getParameter java的问题

时间:2018-10-15 01:16:58

标签: java servlets

@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    request.setAttribute("orden", 11);
    System.out.println("ord "+request.getParameter("orden"));//returns null
    request.getRequestDispatcher("/view/a.jsp").forward(request, response);
}

//Why does this happen?

在我的jsp中是相同的result = null

2 个答案:

答案 0 :(得分:1)

您正在设置attribute并尝试获取parameter

request.setAttribute("orden", 11);
request.getAttribute("orden");

答案 1 :(得分:0)

属性和参数是不同的东西。在设置属性时,请使用getAttribute()获取值。

System.out.println("ord "+request.getAtribute("orden"));