简体   繁体   English

从Servlet获取JSP页面的HTML

[英]Getting Html of a jsp page from a servlet

A jsp page in which dynamic datas are there. 一个包含动态数据的jsp页面。

I want to get the html of the jsp page which is shown in the browser , from the servlet. 我想从servlet获取浏览器中显示的jsp页面的html。

I want to store the html of the jsp in a String variable. 我想将jsp的html存储在String变量中。

is it possible to get the html source of the jsp file from a servlet. 是否有可能从Servlet获取jsp文件的html源。 If yes . 如是 。 How? 怎么样?

Use commons http client, which helps in making GET or POST requests from java application. 使用commons http客户端,它有助于从Java应用程序发出GET或POST请求。

You can pass all the data required like authentication params or.. session id's etc. 您可以传递所需的所有数据,例如身份验证参数或会话ID等。

As per your requirement you can get content of completely rendered HTML source using the same. 根据您的要求,您可以使用该内容获取完全呈现的HTML源的内容。

Much more details can be found here along with good examples 可以在此处找到更多详细信息以及良好的示例

http://hc.apache.org/httpclient-3.x/userguide.html http://hc.apache.org/httpclient-3.x/userguide.html

Unless I'm misunderstanding your question, this is simply a matter of using the wget or curl command (or the Windows equivalent) to fetch the page and save it in a file. 除非我对您的问题有误解,否则这仅是使用wgetcurl命令(或Windows等效文件)来提取页面并将其保存在文件中的问题。

(This won't work if the page contains Javascript that must be executed in order to fetch or render the data. For that use-case, refer to the answers to this question .) (如果页面包含必须执行以获取或呈现数据的Javascript,则此方法将无效。对于该用例,请参考此问题的答案。)

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

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