【问题标题】:Where is the default index.jsp file in a Java EE project in NetBeans?NetBeans 中 Java EE 项目中的默认 index.jsp 文件在哪里?
【发布时间】:2013-06-22 06:09:10
【问题描述】:

我在 NetBeans 中创建了一个简单的 Web 应用程序,名为 WebApplication1。创建了一个名为index.jsp 的文件。当我运行应用程序时,浏览器转到index.jsp。

项目中没有任何地方提到它作为欢迎页面。那么那里的情况如何?

我检查了 build.xml、glassfish-web.xml、所有 XML 文件和 nbproject 文件夹中的 prop 文件,但是无处提及index.jsp。进展如何?

【问题讨论】:

  • 你检查过 web.xml 吗?
  • 是的,什么都没提。

标签: jakarta-ee netbeans glassfish


【解决方案1】:

默认情况下,在 NetBeans 中,如果您创建的项目没有添加框架,则不会提供部署描述符(文件 web.xml)。

要更改它,请右键单击项目并选择New>Other>web>Standard Deployment Descriptor(web.xml)。

现在编辑 web.xml 文件并设置

<welcome-file-list>
    <welcome-file>newjsp.jsp</welcome-file>
</welcome-file-list>

为了将默认更改为文件newjsp.jsp。

明确表示Tomcat...

如果应用程序中没有提供 web.xml 文件,则将 Tomcat 的默认 web.xml($CATALINA_HOME/conf/web.xml) 提供给应用程序。这个部署描述符有以下几行:

<!-- -->
<!-- If you define welcome files in your own application's web.xml -->
<!-- deployment descriptor, that list *replaces* the list configured -->
<!-- here, so be sure to include any of the default values that you wish -->
<!-- to use within your application. -->

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

这就是 index.jsp 文件默认显示的原因。

【讨论】:

  • 对于 http web 服务器它是 index.html ,你确定如果 web.xml 没有定义 welcome-file-list ,容器仍然会选择 index.jsp 吗?
  • @MaVRoSCy 那么,原因是 Glassfish/Tomcat?
  • 如果 web.xml 中没有添加任何内容,并且您有 index.html 和 index.jsp,它将获取 html 文件
  • @The New Idiot 请看我的更新
  • @PhilipRego 现在可能不正确,但你可以理解你真正需要做什么对吗?
【解决方案2】:

如果您使用的是 NetBeans,则需要在项目上单击右键,然后单击属性。将打开一个新的弹出窗口,在左侧菜单上会有一个名为 Run 的标签。单击此处,然后单击“相对 URL”。你应该输入:

./nameOfYourJspFile.jsp

仅此而已!

【讨论】:

  • 这太好了,你能简单地告诉我这意味着什么吗?以及为什么我无法通过使用 来加载页面
【解决方案3】:

确保 JSP 代码文件不在 Web-Inf 目录中。它应该在 Web Pages 目录中。

【讨论】:

    【解决方案4】:

    它可以是 index.html 或 index.jsp,您的 Web 应用程序在 NetBeans 中的欢迎页面。

    此外,NetBeans IDE 8.2 中也存在一个错误:即使您在描述符 web.xml 文件中进行了更改(通过添加“welcome-file-list”标签),“运行”运行旧版本的索引!

    要解决此问题,请将“./index.html”放在项目属性中“运行”类别的“相对 URL”字段中。

    【讨论】:

      猜你喜欢
      • 2013-03-10
      • 1970-01-01
      • 2014-08-23
      • 2011-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多