servlet insde a JSP

时间:2016-10-11 13:59:18

标签: java jsp servlets taglib

我在使用WebLogic服务器的Spring Framework MVC应用程序中工作。我正在使用jstl 1.2。我有一个由我创建的自定义标记库。

我创建了以下标记:

    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);

        }
    }

我已经定义了这个servlet,但是request.getAttribute(&#34; test&#34;)的值是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"));
..
}

和JSP

<tdk:displayImage logo="${logo}"    width="200" />

1 个答案:

答案 0 :(得分:0)

请求不同而且不一样!在为Webbrowser创建HTML时创建DisplayImageTag。在浏览器中接收到HTML后,浏览器决定使用完全不同的请求(没有为html请求设置的属性)从服务器查找图像。