eclipse 动态 web 项目文件位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12902339/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
eclipse dynamic web project file locations
提问by glez
I'm creating a new dynamic web project in Eclipse and was wondering what best practices are for folder taxonomy. Here's what I believe it is <> are folders. Can someone please verify?
我正在 Eclipse 中创建一个新的动态 Web 项目,并想知道文件夹分类法的最佳实践是什么。这是我认为的 <> 是文件夹。有人可以验证吗?
<Eclipse project name>
<src>
-- .java files
<WebContent>
-- .html pages
<images>
<css>
<js>
<META-INF>
MANIFEST.MF
<WEB-INF>
web.xml
<app name>
-- .jsp pages
回答by Jet_C
Here is a sample folder structure of a dynamic web project:
As you can see all static files are placed as sub-folders under the WebContentfolder. By naming conventions .css files are places in the csssub-folder. JavaScript .js files are placed under the jssub-folder and any image files such as .jpeg or .png are placed in the imagessub-folder. I also have an extra libsub-folder where I placed an angularjs library to be used.
如您所见,所有静态文件都作为子文件夹放置在WebContent文件夹下。按照命名约定,.css 文件位于css子文件夹中。JavaScript .js 文件放置在js子文件夹下,任何图像文件(例如 .jpeg 或 .png)都放置在图像子文件夹中。我还有一个额外的lib子文件夹,我在其中放置了一个要使用的 angularjs 库。
By default after creation of a dynamic web project your web.xml file looks like so:
默认情况下,在创建动态 Web 项目后,您的 web.xml 文件如下所示:
`<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>`
meaning it will first call the listed default name files when you run your application. This is why most projects will name the files as index.htmlor index.jsp. NOTE: that my index.html file is directly below the WebContent folder and not in a sub-folder
这意味着它会在您运行应用程序时首先调用列出的默认名称文件。这就是大多数项目将文件命名为index.html或index.jsp 的原因。注意:我的 index.html 文件直接位于 WebContent 文件夹下方,而不是在子文件夹中
Finally you can call/include your static files (.css .js and image files) from your 'index'
file like so:
最后,您可以从您的'index'
文件中调用/包含您的静态文件(.css .js 和图像文件),如下所示:
<link rel="stylesheet" href=css/bootstrap.min.css>
<link rel="stylesheet" href=css/bootstrap-theme.min.css>
<script type="text/javascript" src="lib/angular.min.js"></script>
<script src="js/contactsApp.js"></script>
Also your .java files will properly go in the Java Resources-> src-> {place java files here}
此外,您的 .java 文件将正确放入Java Resources-> src-> {place java files here}
回答by Aleksandr M
Put your pages under WEB-INF
folder, in that way they cannot be accessed directly.
将您的页面放在WEB-INF
文件夹下,这样就无法直接访问它们。
Also look at maven
directory layout http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html.
另请查看maven
目录布局http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html。
回答by Upendra Bittu
To what Aleksandr M said,
对于 Aleksandr M 所说的,
WebContent folder: The mandatory location of all web resources, including HTML, JSP, graphic files, and so on. If the files are not placed in this directory(or in a sub directory structure under this directory), the files will not be available when the application is executed on the server.
WebContent 文件夹:所有 Web 资源的必需位置,包括 HTML、JSP、图形文件等。如果文件没有放在这个目录下(或者在这个目录下的子目录结构中),那么在服务器上执行应用程序时这些文件将不可用。
WEB-INF Based on the Sun Microsystems Java Servlet 2.3 Specification, this directory contains the supporting Web resources for a Web application, including the web.xml file and the classes and lib directories.
WEB-INF 基于 Sun Microsystems Java Servlet 2.3 规范,该目录包含支持 Web 应用程序的 Web 资源,包括 web.xml 文件以及 classes 和 lib 目录。
来源:http: //help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.wst.webtools.doc.user%2Ftopics%2Fccwebprj.html
回答by dataricc
I had this question too and can't comment yet, but Upendra Bittu's answer helped me.
我也有这个问题,还不能发表评论,但 Upendra Bittu 的回答帮助了我。
http://help.eclipse.org/neon/index.jspSearch 'jsp', click on "Creating JavaServer Pages (JSP) files"
http://help.eclipse.org/neon/index.jsp搜索“jsp”,点击“Creating JavaServer Pages (JSP) files”
- Create a dynamic Web project if you have not already done so.
- In the Project Explorer, expand your project and right click on your WebContent folderor on a subfolder under WebContent. Note that if you choose any other folder in which to create the JSP, then it will not be included in the WAR file that is deployed to the server. In addition, link validation will not encompass files that are not under the WebContent folder.
- From the context menu, select New > JSP. The New Java Server Page window appears with your folder selected
- 如果您还没有这样做,请创建一个动态 Web 项目。
- 在 Project Explorer 中,展开您的项目并右键单击您的WebContent 文件夹或 WebContent 下的子文件夹。请注意, 如果您选择任何其他文件夹来创建 JSP,那么它不会包含在部署到服务器的 WAR 文件中。此外,链接验证不会包含不在 WebContent 文件夹下的文件。
- 从上下文菜单中,选择新建 > JSP。New Java Server Page 窗口出现,并选择您的文件夹
I'm trying out tutorials and get lost when people don't say where they create their files, and this helped me understand what's going on, so I'm just passing it on.
我正在尝试教程并在人们不说他们在哪里创建文件时迷路,这帮助我了解发生了什么,所以我只是传递它。
回答by Isaac
I am not sure why having an app-name
directory under WebContent
would be considered a "best practice".
我不确定为什么将app-name
目录下的目录WebContent
视为“最佳实践”。
Other than that, one primary rule you should be following when coming up with a directory structure is to have all static resources under one directory. In your example, I would have a subdirectory called static
under WebContent
, and place the js
, css
and images
directories under it.
除此之外,在提出目录结构时您应该遵循的一个主要规则是将所有静态资源都放在一个目录下。在您的示例中,我将有一个名为static
under的子目录WebContent
,并将js
,css
和images
目录放在其下。
That way, it'd be easier for you to (later on) configure your HTTP server to pick static resources directly from the file system rather than route requests for static resources through the servlet container.
这样,您(稍后)将 HTTP 服务器配置为直接从文件系统中选择静态资源而不是通过 servlet 容器路由对静态资源的请求会更容易。