简体   繁体   English

Java Servlet如何转储静态HTML页面

[英]Java servlet how to dump a static html page

I want to dump a static html page from a servlet. 我想从servlet中转储静态html页面。 With php I would do something like 用PHP我会做类似的事情

$dbdiv = <<<XYZ
<div id="mystaticdiv"></div>
</div>;

Then echo the XYZ 然后回显XYZ

Can this be done with Java servletsa? 可以使用Java servletsa完成吗?

Use RequestDispatcher#forward() or include() , depending on whether it represents full or partial HTML content. 使用RequestDispatcher#forward()include() ,取决于它代表全部还是部分HTML内容。

request.getRequestDispatcher("/WEB-INF/some.html").forward(request, response);

(note that the HTML page is hidden away in /WEB-INF to prevent direct access without invoking the servlet first) (请注意,HTML页面隐藏在/WEB-INF以防止直接访问而无需先调用servlet)

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

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