Location of eclipse dynamic web projects

I am creating a new dynamic web project in Eclipse and wondering what works best for folder taxonomy. Here, I believe this is & lt; > - folders. Can anyone confirm this?

<Eclipse project name> <src> -- .java files <WebContent> -- .html pages <images> <css> <js> <META-INF> MANIFEST.MF <WEB-INF> web.xml <app name> -- .jsp pages 
+4
source share
5 answers

Here is an example folder structure of a dynamic web project: enter image description here

As you can see, all static files are placed as subfolders in the WebContent folder. By named convention, .css files are places in the css subfolder. JavaScript.js files are placed in the js subfolder, and any image files, such as .jpeg or .png, are placed in the images subfolder. I also have an additional lib subfolder where I placed the angularjs library to be used.

By default, after creating a dynamic web project, your web.xml file looks like this:

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

means that when you first start the application, it will first call the listed default name files. This is why most projects will name the files as index.html or index.jsp . NOTE: my index.html file is located directly under the WebContent folder, not in a subfolder

Finally, you can call / include your static files (.css.js and image files) from your 'index' file as follows:

  <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 be correctly placed in Java resources β†’ src β†’ {here java files are here}

+4
source

Put your pages in the WEB-INF folder, so they cannot be accessed directly.

Also look at the maven catalog layout http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html .

+3
source

I'm not sure why having an app-name directory under WebContent would be considered "best practice."

In addition, one of the basic rules that you must follow when creating a directory structure is to have all static resources in one directory. In your example, I would have a subdirectory called static under WebContent and place the js , css and images directories under it.

Thus, it will be easier (later) to configure your HTTP server to select static resources directly from the file system, and not to route requests for static resources through the servlet container.

+1
source

What Alexander M said

WebContent folder: Mandatory location of all web resources, including HTML, JSP, image files, etc. If the files do not fit in this directory (or in the subdirectory structure in this directory), the files will not be available if the application is running on the server.

WEB-INF Based on the Sun Microsystems Java Servlet 2.3 specification, this directory contains supporting web resources for the web application, including the web.xml file and class directories and lib.

Source: http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.wst.webtools.doc.user%2Ftopics%2Fccwebprj.html

+1
source

I also had this question and I can not comment, but Upendra Bittu's answer helped me.

http://help.eclipse.org/neon/index.jsp Find "jsp", click on "Create JavaServer Pages (JSP) Files"

  • Create a dynamic web project if you have not already done so.
  • In the Project Explorer, expand the project and right-click on the WebContent folder or in a subfolder under WebContent. Please note that if you select any other folder to create the JSP, it will not be included in the WAR file, which will be deployed to the server. In addition, link checking will not include files that are not in the WebContent folder.
  • From the context menu, select New> JSP. The "New Java Server Page" window appears with the folder selected

I test textbooks and get lost when people don’t say where they create their files, and it helped me understand what is happening, so I just pass it on.

+1
source

Source: https://habr.com/ru/post/1439887/


All Articles