Inaccessible
Inaccessible

Reputation: 1560

Welcome file in java

I don't know how to access the html(fp.html) file under webcontent folder.

Deployed app structure

fp(app name)
|__ fp.html
|__ META-INF  
|__ WEB-INF

My web.xml has this configuration

    <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>fp</display-name>
  <servlet>
    <servlet-name>FpServlet</servlet-name>
    <servlet-class>com.fp.FpServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>FpServlet</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
     <welcome-file>fp.html</welcome-file>
  </welcome-file-list>
</web-app>

If I access the file localhost:8080/fp/fp.html like this, It shows 404 error. But accessing localhost:8080/fp/ working fine.

Kindly help me to overcome this problem.

Upvotes: 0

Views: 192

Answers (1)

jbx
jbx

Reputation: 22188

Remember that Tomcat can host multiple applications. So in general your folder structure would look something like this:

~/<yourtomcatfolder>/webapps/<yourapplication>

You put any HTML files you want to access directly under that folder, which means you can then access the file like this:

http://localhost:8080/yourapplication/fp.html

Obviously the port and everything is configurable, so the above is just an example. You put also any CSS and JS files similarly, and you can have sub-folders.

Then you put your classes (servlets etc.), libraries etc. under the special WEB-INF folder under your application's directory.

~/<yourtomcatfolder>/webapps/<yourapplication>/WEB-INF/classes ~/<yourtomcatfolder>/webapps/<yourapplication>/WEB-INF/lib

Anything under WEB-INF is not accessible from outside (so no one can download your class files and decompile them etc.)

Upvotes: 1

Related Questions