user602774
user602774

Reputation: 1103

convert java server pages to servlets

is it possible to convert java server pages to servlets ?

Upvotes: 2

Views: 3904

Answers (5)

Deepak Ugale
Deepak Ugale

Reputation: 1

Tomcat/work/Catalina/localhost/[my-web-app]/org/apache/jsp

lukastymo he say right but you just rename the class name and file name to JSP convert to Servlets But it is not necessory

Upvotes: 0

Julian
Julian

Reputation: 1732

If you want to do the translation on the command line, you could use https://github.com/bnoqlr/jsppreproc which is just a wrapper for jspc. After compiling the wrapper by running mvn package, you can simply run java -jar target/jsppreproc-1.0-SNAPSHOT.jar -d /tmp some.jsp. You will find the servlet (.java file) with inside the /tmp directory.

Upvotes: 1

Powerlord
Powerlord

Reputation: 88796

JSPs are compiled to a Servlet on the server the first time you access them. This is one of the reasons why you need a JDK instead of a JRE when running a Servlet container or Java EE stack... unless the server itself comes with a Java compiler, like Tomcat does.

Depending on the server, there may be methods to precompile JSPs when you initially deploy the application, or if you deploy using Maven, by configuring Maven to use the jspc plugin.

Upvotes: 3

lukastymo
lukastymo

Reputation: 26809

jsp files are compiled to servlets automaticly, so you needn't compile by yourself. If you are using Tomcat you can look at this servlets - java classes. It's in:

Tomcat/work/Catalina/localhost/[my-web-app]/org/apache/jsp

Work directory is created when you start your Tomcat server, so before you check, start Tomcat :)

If you are using different container check documentation.

Upvotes: 2

Luixv
Luixv

Reputation: 8710

jsp are compiled to servlets. In fact you might have a jsp which does not render anything and which is going to be your servlet. BTW, why do you want to do something like this?

Upvotes: 1

Related Questions