Hi, i want to convert a .jsp file to .java file. I read various forums and they said to use tomcat to convert .jsp to .java.I have ran tomcat but it is not doing anything(i cannot write anything). Through command prompt i ran it and it just opens a new tomcat window and does nothing.May be i am missing the whole point here.Please help and suggest what to do and how to do that.

Dani AI

Generated

You are not missing the point, is right to question the goal. A JSP is not something you run like a desktop .java file; it is translated by the server into a servlet and executed inside a servlet container (Tomcat, JBoss, etc.). Tomcat’s JSP engine (Jasper) does this translation automatically the first time the page is requested. (tomcat.apache.org)

If you only want to see the generated .java for learning/debugging:

  • Deploy your JSP inside a webapp (for example, webapps/myapp) and request it in a browser (). Tomcat writes the generated sources under the server’s work directory, which lives beneath $CATALINA_BASE/work. Each webapp gets its own subdirectory there. (tomcat.apache.org)
  • Ensure Jasper is keeping sources by leaving the init-param keepgenerated as true (it is true by default). That makes Tomcat retain the page_jsp.java next to the compiled class. (tomcat.apache.org)

If you need the .java without hitting the page at runtime, precompile the JSPs. Tomcat provides the Jasper Ant task (jspc) that emits Java sources into WEB-INF/src and classes into WEB-INF/classes. A minimal Ant target looks like this:

<import file="${tomcat.home}/bin/catalina-tasks.xml"/>
<target name="jspc">
  <jasper uriroot="${webapp.path}"
          outputDir="${webapp.path}/WEB-INF/src"
          webXmlInclude="${webapp.path}/WEB-INF/generated_web.xml"/>
</target>

Run it with Ant and your TOMCAT_HOME/WEBAPP_PATH set; this is the supported way to convert JSPs to servlets offline. (tomcat.apache.org)

Finally, , if the end goal is to run a “game” inside Eclipse as a desktop app, converting JSP to .java will not help. A JSP-based app runs in a web container; you would either run Tomcat from Eclipse and use a browser, or obtain the game’s actual Java application code.

Recommended Answers

All 12 Replies

AFAIK,

jsp converted into servlet by any application server(tomcat,jboss ,etc) automatically...

servlet file itself a java file...

so you no need to convert it as java by yourself...

want to convert a .jsp file to .java file

Can you give an example.
I think you are correct when you say:

May be i am missing the whole point

Ok i have a html page which i have to convert to .java file.I used html converter to convert the page to a .jsp file and now i have to convert it to .java file.According to the replies when i run TOMCAT,it should automatically create the file but i do not see it(well i searched the .java file).Here is the screenshot of the Tomcathttp://img375.imageshack.us/i/captureic.jpg/

Converting an HTML page to java source code (a .java file) makes no sense.
HTML is a Markup Language.
Java code is source for an executable program. Vastly different things.

There's something missing in your description of what you want to do.

Are you trying to write a .jsp file that will generate an HTML page?
A .jsp file is a mix of HTML and java source.

i also have the .jsp file that i have to convert to .java

Converting an HTML page to java source code (a .java file) makes no sense.
HTML is a Markup Language.
Java code is source for an executable program. Vastly different things.

There's something missing in your description of what you want to do.

Are you trying to write a .jsp file that will generate an HTML page?
A .jsp file is a mix of HTML and java source.

How are you going to use the .java source file you are creating from a .jsp file?

I have the .jsp file and now i have to make it a readable file for java virtual machines such as(secure shell or eclipse) and i believe one can only run the .java files in order to use these virtual machines.

How are you going to use the .java source file you are creating from a .jsp file?

What will you do with the .java file after you compile it to a .class file?
Will it be a standalone application that you run on the desktop?
Or will it only execute within some server with a special environment?

well its a game that i am trying to run on eclipse

What will you do with the .java file after you compile it to a .class file?
Will it be a standalone application that you run on the desktop?
Or will it only execute within some server with a special environment?

Sorry, I have no idea how your IDE works.

create a web project as web standard prj_name/web-inf
web-inf/web.xml
place .jsp where ever u want and open command prompt change directory to .jsp having floder

run the setDomainEnv.cmd or . setDomainEnv.sh(linux) from ur command prompt (use cd to locate upto use
cd bea/user_prject/domains/anydomain(ur choice)/bin) and come back cd .. upto ur .jsp file containing folder run the following command

java weblogic.jspc -keepgenerated index.jsp

it works fine
posted by (asraju)

asraju: after two years, I doubt this was still an issue. also, it's nonsense anyway. decently designed and written jsp files don't contain Java code to begin with.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.