• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

display html in jsp using struts action

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a struts action. I am getting a url from database which consist the path of html file on server. I want to display that file on my jsp.

Can anyone help out with a sample code. How to render the html page on my struts forward.

Please help...its urgent.
 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add the url in the request attribute and take it out in the JSP to include the html in the JSP.

You could also do a redirect in your action to the html page from your action class.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could simply define a local forward that forwards to the HTML page and have your action class find and return that forward. There's no law that says a forward has to be a JSP.
 
paresh doshi
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Amit,

As per your suggestion, i have forwarded to an jsp which has included the html..

but it is not able to get the absolute path of the html file. I have used the following tag.

<%@ include file="C:\Javaranch.html" %> //my file is in C:\Javaranch.html

but it is not able to get the path as it is searching in the forward path jsp folder.

Can you please help out.
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi paresh,
execute method requires an ActionForward object....I think this might help you...
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by paresh doshi:
my file is in C:\Javaranch.html


None of the techniques suggested by any of us will work unless the html file is in the context root of your application or one of its subdirectories.

If you need to display a file that is outside of the context root, you would need to use the classes in the java.io package to read the file and output it to the HTTPServletResponse object's output stream.
 
paresh doshi
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Merrill,

Thanks for your reply. I have tried in similar manner using File objects. I have used the following code.

response.setContentType("text/html");
File f = new File ( "C:\\jboss-4.0.3SP1\server\\default","Javaranch.html");
FileInputStream fis = new FileInputStream(f);
byte[] btData = new byte[(int)f.length()];
int iBytesRead = fis.read(btData);
System.out.println("Before Creating OutputStream");
ServletOutputStream out = response.getOutputStream();
DataOutputStream out = new DataOutputStream( res.getOutputStream() );
System.out.println("Before Writing OutputStream");
out.write( btData);


This code is rendering the html file, but the images are not loaded.

Can you help me out in that... or is there any other way to render html file(lying in JBOSS_HOME location or any absolute path) using struts action.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, is there a reason these files have to be outside the context root? It would be so much simpler to deal with them if you could just move them inside the context root.

You run into the same problem with image files outside the web context root as you do with html files. You will have to create an Action class that will read an image file and output it to the HTTPServletResponse object's output stream.

Then in your HTML file, you will have to reference the Action class you created in your <img> tag. Example:
 
reply
    Bookmark Topic Watch Topic
  • New Topic