-1

I am working in Spring Framework MVC application with WebLogic server. I am using jstl 1.2. and I have a custom taglib created by me.

I have created the below Tag:

    public class DisplayImageTag extends SimpleTagSupport {

        private Collection<Image> images;
        private Byte[] logo;
        private String action;

        @Override
        public void doTag() throws JspException, IOException {

            PageContext pc = (PageContext)getJspContext();
            JspWriter out = getJspContext().getOut();               
            pc.getRequest().setAttribute("test", "test");
            String fullPath = TDKUtils.getTDKPath(pc);

sb.append("<img src='" + fullPath + "/displayImage?resize=true' align='bottom' />");
out.print(sb);

        }
    }

I have defined this servlet, but the value of request.getAttribute("test") is null ! ?

public class DisplayImageServlet extends HttpServlet {


    @SuppressWarnings("unchecked")
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

        System.out.println ("test ---> " + request.getAttribute("test"));
..
}

and the JSP

<tdk:displayImage logo="${logo}"    width="200" />
Rohit Gaikwad
  • 3,677
  • 3
  • 17
  • 40
Amadeu Cabanilles
  • 913
  • 3
  • 19
  • 47
  • 1
    There's some missing code here... where is the JSP? What's probably happening is doGet() is called before doTag(), so test wouldn't be in the request. – Christopher Schneider Oct 11 '16 at 14:09

1 Answers1

0

The requests are different and not the same! The DisplayImageTag is created while creating the HTML for the Webbrowser. After receiving the HTML in the browser, the browser decides to lookup for the image from the server using a compleatly different request(not having the attribute you set for the html-request).

Grim
  • 1,938
  • 10
  • 56
  • 123