【问题标题】:servlet insde a JSPJSP 中的 servlet
【发布时间】:2016-10-11 13:59:17
【问题描述】:

我正在使用 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" />

【问题讨论】:

  • 这里缺少一些代码... JSP 在哪里?可能发生的情况是 doGet() 在 doTag() 之前调用,因此测试不会在请求中。

标签: java jsp servlets taglib


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-14
    • 2017-01-11
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多