Percy
Percy

Reputation: 13

Problem with servlet request setAttibute and getParameter java

@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?

and in my jsp is the same result = null

Upvotes: 1

Views: 33

Answers (2)

Roshana Pitigala
Roshana Pitigala

Reputation: 8796

You are setting an attribute and trying to get a parameter

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

Upvotes: 1

Ramesh Kotha
Ramesh Kotha

Reputation: 8322

attribute and parameter are different things. As you are setting attribute, use getAttribute() to get the value.

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

Upvotes: 0

Related Questions