Programmatically invoke the JSP parser

I want to programmatically call the JSP parser. This means that I want Java to be able to “launch” the jsp page and get its output without sending it back to the client (I really want to save the output to a file). I do not want to “forward” the request to the JSP page. I want to be able to do this on several pages of JSP in a row.

What is the best way to do this?

I found this question , but BalusC does not directly answer the question.

If you're interested, I need to do this because I want to “precompile” the JSP for use on platforms other than the Java servlet container.

EDIT

What I need is not a .class file, but HTML output. In fact, it will be static when it was generated, but I have some custom jsp tags, and I want to use the JSP parser to extend them.

+3
source share
4 answers

I am not sure that I understand the essence of all this.

JSPs are parsed and precompiled to files .class. At this point, they are Java servlets. To execute them, you need a servlet mechanism.

If you intend to grab the generated HTTP response as a “precompiled” response, this assumes that there is no dynamic content, and each time you send this particular request, each response will be the same. If so, then you have static HTML.

, .

JSP .class, , Java EE JSP. JSP Tomcat WebLogic.

+1

html jsp - -, .

, , , Selenium , HttpUnit.

, JSP-.

+1

JSP . , , JSP , .

, JSP , , HttpClient, JSP HTML. , -. JSP Parser, .

But if your JSP is dynamically constructed, you should look at options in which your HTML can be generated on the Java side. But if it involves creating rule-based HTML, you better create it in Java. You can use the ECS Apache Jakarta library for this.

And yes, JSPs are not intended for this purpose.

0
source

Source: https://habr.com/ru/post/1790858/


All Articles