简体   繁体   English

如何从Servlet获取JSP页面的内容?

[英]how to get the content of JSP page from the Servlet?

I need to get the content of a jsp page from a servlet without redirect or forward, like a file for security issues, I'll process the HTML and write the new generated HTML in the servlet response. 我需要从servlet获取jsp页面的内容而不进行重定向或转发,例如用于安全性问题的文件,我将处理HTML并将新生成的HTML写入servlet响应中。 How can I do that? 我怎样才能做到这一点?

An example of what I'm trying to do: 我正在尝试做的一个例子:

if (request.getParameter("pageName").equals("index")) {
    //get index.jsp content and process it...
}

You can't do that in a servlet, but you could do it in a Filter, in the doFilter method. 您不能在servlet中执行此操作,但是可以在doFilter方法的Filter中执行此操作。 You would need to provide a wrapper around the response object, something like what they do here . 您将需要在响应对象周围提供包装器,就像它们在这里所做的一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM