Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

where to store the .htm files related to the servlet

 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
All the .html files related to a servlet are stored into which directory for the tomcat server?
thanks,
Trupti
 
Omar IRAQI
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi nigam,
When Apache receives a static request that concerns an html file, it does not forward it to Tomcat. Consequently, the html file is resolved with respect to Apache document root.
Now if you are using tomcat as a web server, the default document root is : $TOMCAT_HOME/webapps/ROOT/
Regards
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
trupti
Not to be smart about it but they go somewhere under the root of the web app. If you only have a few then just go ahead and put them in the root of the webapp if there are a lot of them you can create a directory structure under the root.
Then if you need to include or forward to one of them just use the path that starts at the context root, with a '/' and the container will be able to find it.
For example, you have an app named myApp in the webapps folder. In the myApp folder you could have your index page and another folder to hold html pages related to inventory control, it would look something like this:

Now in servlet1 to include one of the inventory pages, do this:
request.getRequestDispatcher("/inventory_pages/page1,html");
hope that helps
 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I have stored the .html file under install-dir/webapp/root/classes directory ,but when i try to access it as http://localhost:8080/servlet/ThreeParams.html i get an error message 404 that the file is not found.
thanks,
trupti
 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I have stored the .html file under install-dir/webapp/root/classes directory ,but when i try to access it as http://localhost:8080/servlet/ThreeParams.html i get an error message 404 that the file is not found.
thanks,
trupti
 
Joel Cochran
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trupti,
I wouldn't put anything but Servlets in the web-inf/classes directory. For one thing, there is some XML magic that happens in the background when you use /servlet/ that probably precludes regular files from being served from there.
Look at Dave's post again and put your HTML file in the root directory of your WebApp, then point your browser to:
http://localhost:8080/myWebApp/ThreeParams.html
GL,
 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
joel,
I have put my htm file under
webapps/myhtmfiles/Threeparams.htm
now when i try to access it i get the 500 error saying that no context configured to process this request..
i Have put the servlet class files under webapps/root/WEB-INF/classes directory..

where am i going wrong?
thanks,
Trupti
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trupti
If the file is in a subdirectory then you need to add the subdirectory to the path you're trying to access it on:
http://localhost:8080/myWebApp/myhtmfiles/ThreeParams.html
Also, have you done anything to the web.xml file? You dont need to change anything in that file to just serve HTML pages, unless you are rying to map them to different names or something like that. If that is your ultimate goal then try doing it the simple way first, just to make sure it works then you can add different things to it.
[ June 26, 2002: Message edited by: Dave Vick ]
 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
I have a html file. named ThreeParamsForms.htm stored under c:\tomcat\webapps\myhtmfiles\*.htm directory.
The servlet class file threeparam.class file is stored under c:\tomcat\webapps\root\WEB-INF\classes\threeparam.class dirctory.
I have not registered this servlet under the web.xml file.
While accessing the htm file i access it through the following url..
http://localhost:8080/myhtmfiles/ThreeParamForms.htm
but i am getting http 404 error.
thanks,
Trupti
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trupti
The files for the html need to be in a web application or you need to have a web.xml file to tell tomcat where to find them. Is the folder myhtmfiles a web application, doe sit have a WEB-INF directory? and a web.xml file?
If not then just typing the location of the file into the address line wont locate it as it has to be in an application.
Your servlet on the other hand is part of the root web app so it'll be fine. In the web.xml file under the root you can map to the html files and tell the container that they are in the other directory, but I pretty sure that only works for URI that would point to the root web app then the container would know that to go to the myhtmfiles directory to get them.
Try putting a WEB-INF folder in the myhtmfiles directory and a web.xml file, an empty one should even work. then restart tomcat so it recognizes it as a web application and it should work.
If these two are related (the html files and the servlet classes) then your best bet is to create a new web application under the tomcat/webapps and put all of the files in there. You'll need a WEB-INF directory and a web.xml file but then you should be all set.
Since this is more of tomcat problem you might be able to get better answers in the tomcat forum - I'm not a tomcat expert.
hope this helps
 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave,
Thanks a lot..
i was able to access the html file when i created a new folder with web-inf & web.xml folder & file in it respectively..as told by you..
trupti
 
sim sim
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Trupti,
Put your myhtmfiles under webapp/ROOT directory. They should work them
c:\tomcat\webapps\ROOT\myhtmfiles\*.htm
I hope this works.
Sim Sim.
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trupti
Glad you got it to work!! Good luck with it and if you have more quetions just let us know.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic