"Java.web" to create a simple Java Web project __java

Source: Internet
Author: User

Use Maven in eclipse to create a WebApp project, choose the following Archtype type:



The resulting project structure is as follows:



The default generated pom.xml files are as follows:

<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" > <modelversion >4.0.0</modelVersion> <groupId>com.gof</groupId> <artifactid>base-webapp</ artifactid> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name> Base-webapp Maven webapp</name> <url>http://maven.apache.org</url> <dependencies> <d ependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <versio N>3.8.1</version> <scope>test</scope> </dependency> <!--Servlet--> &L t;dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> &L T;version>2.5</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <ar tifactid>jsp-api</artifactid> <version>2.1</version> <scope>provided</scope> &L t;/dependency> <dependency> <groupId>javax.servlet</groupId> <artifactid>jstl</art ifactid> <version>1.2</version> </dependency> </dependencies> <build> &
 Lt;finalname>base-webapp</finalname> </build> </project>

Note: Sevlet-api and Jsp-api Package Dependency dependency property scope = provided, because the Tomcat container itself provides these two jar packages, so it is only required at compile time. The runtime actually uses a jar package for the Tomcat container. The two jar packages are also not published to Tomcat and are not included in the last generated war package.

The following figure, the publish directory in Eclipse, contains only one of the Dependency-jstl:



The WEB deployment assembly settings are as follows:



Rewrite Web.xml as follows:

<?xml version= "1.0" encoding= "UTF-8"?> <web-app version= "2.5" xmlns= "http://java.sun.com/xml/ns/"
Java ee "
	xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "
	xsi:schemalocation=" http://java.sun.com/ Xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd ">
	
  <display-name>base java webapp< /display-name>
  <description>a Basic Maven Java Webapp application</description>
  
  < welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
</web-app>


Publish the current web app to Tomcat, access the following URL:

http://localhost:8080/base-webapp/


The page is as follows:




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.