Amira Manai
Amira Manai

Reputation: 2599

How to display the code of a java class in a web page (jsp)

I'm developing a web page containing a list of existing java class name :

so when the user click the link of the java class name a new web page is opened containing the code of this java class . so to do it i will use a flow to read the file (java class) and write it on a web page . Have you another optimized solution ?

Upvotes: 0

Views: 802

Answers (4)

madhairsilence
madhairsilence

Reputation: 3880

There is a new project called back2Code, which will decompile class files back to source code.

http://code.google.com/p/back2code/

  1. Store the class files a location in server
  2. Read the appropriate file.
  3. Use the API to decompile it to the source code.
  4. Display the source code , appropriately.

Upvotes: 2

KV Prajapati
KV Prajapati

Reputation: 94653

Use <c:import /> JSTL and embed the content in <pre></pre> tag.

<c:import var="content" url="File.java"/>
<pre>
 <c:out value="${content}"/>
</pre>

Upvotes: 4

corsair
corsair

Reputation: 668

For each java class generate a static html page and on click simple open that page.

Upvotes: -2

Jon Taylor
Jon Taylor

Reputation: 7905

Just read the .java file like any other text file. Note make sure you are doing it with the .java files and not compiled .class files.

You can then optionally format it.

Upvotes: 3

Related Questions