如何将jsp文件放在单独的文件夹中? [英] How to put jsp files in a separate folder?

查看:160
本文介绍了如何将jsp文件放在单独的文件夹中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Web内容下有7个jsp页面时,它工作正常,但是当我将所有jsp文件放在Web内容中名为"jsp"的文件夹下时,我的浏览器无法找到这些页面.我已经尝试过通过更改web.xml中的路径来进行尝试.

When I had 7 jsp pages under web-content, it was working fine, but when I am putting all the jsp files under a folder named "jsp" in web-content, my browser is unable to find the pages. I have tried just by changing the path in web.xml.

任何帮助将不胜感激.

我应该使用 jsp:include

推荐答案

作为Web应用程序的一部分,我们应该维护标准的文件夹结构. IE 然后应在其中包含web.xml文件的WEB-INF文件夹中找到ProjectFolder.

As part of web applications we should maintain a standard folder structure. i.e ProjectFolder then inside WEB-INF folder which consists the web.xml file should be there.

我们可以将jsp文件保留在项目目录中的任何位置.基于此,我们应该形成URL.

We can keep jsp files any where in the project Directory. Based on that we should form URL.

例如: 我有项目"Demo",并且内部有"WEB-INF",并且WEB-INF包含web.xml文件. 我已经将我的jsp文件(例如:jsp1,jsp2,jsp3 ..)直接放在演示"文件夹中

Ex: I have project "Demo" and Inside "WEB-INF" is available and WEB-INF contains web.xml file. I have placed my jsp files ex: jsp1,jsp2,jsp3.. directly inside the "Demo" folder

所以我应该使用以下URL访问这些jsp.

So i should access these jsp's using following URL.

[例如:http://localhost:8080//Demo/jsp1.jsp]

[ex: http://localhost:8080//Demo/jsp1.jsp]

方案2:我将我的jsp文件放置在"myjsp"文件夹中,例如:jsp1,jsp2,jsp3...现在,我将"myjsp"文件夹直接放在演示"文件夹中.

Scenario 2: I have placed my jsp files ex: jsp1,jsp2,jsp3.. inside "myjsp" folder. now i placed "myjsp" folder directly inside the the "Demo" folder.

所以我应该使用以下URL访问这些jsp. 注意:-我使用的是Tomcat服务器,端口号为8000.

So i should access these jsp's using following URL. Note:- I am using Tomcat server with 8000 as port number.

[例如:http://localhost:8080//Demo/myjsp/jsp1.jsp]

[ex: http://localhost:8080//Demo/myjsp/jsp1.jsp]

结论:

  • 如果将jsp文件放置在项目目录中的WEB-INF文件夹之外,则可以通过形成URL直接访问这些jsp或网络资源.在这里,我们无需在web.xml的配置文件中配置任何内容
  • 如果我们想将jsp放在WEB-INF文件夹中,那么我们应该配置web.xml来访问那些jsps. 例如:
  • If we place the jsp files outside the WEB-INF folder in project directory then we able to access those jsp's or net resources directly by forming the URL. Here we no need to configure anything in the configuration file in web.xml
  • If we want to place the jsp's inside the WEB-INF folder, then we should configure the web.xml to access those jsps. ex:

方案3:我将我的jsp文件放置在"myjsp"文件夹中,例如:jsp1,jsp2,jsp3...现在我将"myjsp"文件夹放在"WEB-INF"文件夹中.

Scenario 3: I have placed my jsp files ex: jsp1,jsp2,jsp3.. inside "myjsp" folder. now i placed "myjsp" folder inside the the "WEB-INF" folder.

由于WEB-INF目录是私有目录,现在我们将无法直接访问这些jsp页面. 我们需要按如下所示配置web.xml.

Now we will not able access these jsp pages directly, Since WEB-INF directory is private directory. we need to configure the web.xml as shown below.

  <web-app>

<servlet>
    <servlet-name>jsp1</servlet-name>
    <jsp-file>/WEB-INF/myjsp/jsp1.jsp</jsp-file>
</servlet>

<servlet-mapping>
    <servlet-name>jsp1</servlet-name>
    <url-pattern>/jsp1</url-pattern>
</servlet-mapping>

   </web-app>

因此,我们应该使用以下URL访问这些jsp.

So we should access these jsp's using following URL.

[例如:http://localhost:8080/Demo/jsp1]

[ex: http://localhost:8080/Demo/jsp1]

这是我的serverurl =本地主机和端口号= 8080

Here my serverurl= localhost and port number=8080

这篇关于如何将jsp文件放在单独的文件夹中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆