0

I am uploading an image through Servlet.

try{
    //Image Upload Code
} catch(Exception e){
    //Exception Handler
} finally {
    request.setAttribute("job-id", jobId);
    request.setAttribute("message", message);
    System.out.println("SJA : " + message);
    getServletContext().getRequestDispatcher("ReloadJob.jsp").forward(request, response);
}

Then, on ReloadJob.jsp, I am trying to use these attached attributes:

String jobId = request.getParameter("job-id");
String message = request.getParameter("message");
System.out.println("RJ : " + jobId);
System.out.println("RJ : " + message);

This whole process prints following output:

SJA : MESSAGE RECEIVED
RJ : BYWEGRI76T46U34T
RJ : null

Why is message variable null?

rupinderjeet
  • 2,984
  • 30
  • 54

2 Answers2

1

try to use

   String message=(String)request.getAttribute("message");
Musaddique S
  • 1,539
  • 2
  • 15
  • 36
1

String message=(String)request.getAttribute("message");

getParameter() returns http request parameters. Those passed from the client to the server.

getAttribute() is for server-side usage only - you fill the request with attributes that you can use within the same request.

For example - you set an attribute in a servlet, and read it from a JSP. It can be used for any object, not just string.

P S M
  • 1,121
  • 12
  • 29