简体   繁体   English

Java中的欢迎文件

[英]Welcome file in java

I don't know how to access the html(fp.html) file under webcontent folder. 我不知道如何访问webcontent文件夹下的html(fp.html)文件。

Deployed app structure 部署的应用程序结构

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

My web.xml has this configuration 我的web.xml具有此配置

    <?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. 如果我这样访问文件localhost:8080 / fp / fp.html,它将显示404错误。 But accessing localhost:8080/fp/ working fine. 但是访问localhost:8080 / fp /可以正常工作。

Kindly help me to overcome this problem. 请帮助我克服这个问题。

Remember that Tomcat can host multiple applications. 请记住,Tomcat可以托管多个应用程序。 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: 您可以将要访问的任何HTML文件直接放在该文件夹下,这意味着您可以按以下方式访问文件:

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. 您还可以类似地放置任何CSS和JS文件,并且可以具有子文件夹。

Then you put your classes (servlets etc.), libraries etc. under the special WEB-INF folder under your application's directory. 然后,将您的类(servlet等),库等放在应用程序目录下的特殊WEB-INF文件夹下。

~/<yourtomcatfolder>/webapps/<yourapplication>/WEB-INF/classes ~/<yourtomcatfolder>/webapps/<yourapplication>/WEB-INF/lib ~/<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.) WEB-INF下的任何内容都无法从外部访问(因此,没有人可以下载您的类文件并对其进行反编译等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM