开发者

How to deal with the contents of the webpage inside my application

开发者 https://www.devze.com 2023-03-15 12:16 出处:网络
My system (I am using JSP)deals with an existing website on the web. My applicationshould be able to disp开发者_Go百科lay the pages of that website with some changes for example highlight some words.

My system (I am using JSP) deals with an existing website on the web. My application should be able to disp开发者_Go百科lay the pages of that website with some changes for example highlight some words.

So what my program will do is bringing the page from that website and highlight some specific words then display the page again with highlighted words to the user of my system.

How can I do that using java?


you can use Tika to obtain the HTML content (or any other tool, if you are already using something). then use a <span/> to highlight the piece of text which needs to be highlighted & render the page.

its important to consider different markup's.

also, an easier solution would be to use javascript (jquery in specific) which would make the entire process a lot simpler. jQuery library


I'd save XPath or other identification of desired DOM nodes and use it for parametrization of some JavaScript code which can be injected by Java, why not.

Or you can just inject span tags around your words, give them some id and injects CSS for theses ids. That calls for some regular epxpressions, no library is needed.


You're apparently trying to build a filter between the original page and the manipulated page. So in your JSP, you read the original page as text. If it's on your own server, you can just open the file and read it. Or you may need to create a Socket to read it across the Internet. Either way, you read it as text, insert whatever additional markup you need, and then write this marked-up version as the output of your JSP. Your JSP would then have no actual content itself, all the output would be produced within <% and %> with out.println statements. (JSP is not the most natural choice here, you might want to look into servlets, but whatever. There's nothing inherently wrong with a JSP with no actual text.)

0

精彩评论

暂无评论...
验证码 换一张
取 消