How to access JSP implicit objects like (request , response) in Java

后端 未结 3 1720
南方客
南方客 2021-01-23 15:03

How to pass JSP implicit objects like (request, response) in Java. I want to access JSP Implicit Objects in Java code. Please suggest how to achieve this?

My Jav

3条回答
  •  迷失自我
    2021-01-23 15:42

    You can pass objects to the bean using and EL expressions. You have to modify the bean for getter and setter methods.

    public class SomeBean {
      String punchOutRes = null;
      HttpServletResponse response;
      HttpServletRequest request;
    
      public HttpServletResponse getResponse() {
        return response;
      }
    
      public void setResponse(HttpServletResponse response) {
        this.response = response;
        try {
          response.getWriter().println("Some Output");
        } catch (IOException e) {
          e.printStackTrace();  
        }
      }
    
      public HttpServletRequest getRequest() {
        return request;
      }
    
      public void setRequest(HttpServletRequest request) {
        this.request = request;
      }
    
      public String getPunchOutRes() {
        response.setContentType("text/xml");
        return "testing";
      }
    }
    

    then use in the JSP

    
    
    
    

提交回复
热议问题