Alex Ivasyuv
Alex Ivasyuv

Reputation: 8814

How to call JSP from Java stand-alone program

How can I call a JSP file from a Java application, and pass to it a Java Bean, so that as a result I can get a rendered HTML code as output. The Java program is a stand-alone application, that runs by someone. No servlet please.

Upvotes: 0

Views: 966

Answers (3)

LHA
LHA

Reputation: 9645

If Non-Servlet environment & it is a stand-alone application so I think you can use any String template such as Velocity, FreeMaker instead of using JSP.

Upvotes: 3

Serge Ballesta
Serge Ballesta

Reputation: 148880

Mostly a complement to @AppsLandia's answer.

Even if it looks like a template engine, JSP is not. JSP files are first translated into Java source servlets and then compiled to .class normal servlets. That's the reason why they cannot be used outside of a web application running on a servlet container like Tomcat or Jetty or...

Velocity and FreeMarker can be used in web applications, but they are general template engines, so you should have a look to them.

Upvotes: 1

Joop Eggen
Joop Eggen

Reputation: 109547

A JSP is a servlet too. So you need all those Java EE classes, and hence also an implementation by some provider (Java EE container). You could use jetty as an embedded Java EE container.

You can then via URL get the generated HTML page.

If you want minimal JSP functionality, more a scriptable HTML template engine, look at StringTemplate or Velocity or whatever.

Upvotes: 1

Related Questions