JSP 内的 servlet

servlet insde a JSP

我正在使用 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("test")的值是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" />

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