Learn the first day of Java

Source: Internet
Author: User

1. Environment Configuration

A) Java 1.7

b) Eclipse Luna

c) Maven3.2.5

d) Spring 4.1.4

2. Create maven Engineering

A) Open Eclipse,file->new->project->maven->maven project

b) Next

c) Select the created project as WebApp, next

d) Fill in the project's group ID and artifact ID. In general, the group ID write the reverse of the domain name, artifact ID write the project name. The final point is complete.

e) After the initial construction, the project directory structure is as follows

f) in the General project directory, under the Java Resources Directory, there is also the Src/main/java,src/main/test/java,src/main/test/resources three source folder, which needs to be created manually. In the following steps, you will learn how to make up these three directories.

3. Modify project Basic Settings

A) Right-click on this project name->properties->java Build path and tap the Source tab.

b) prompt Hello/src/main/java (missing) and Hello/src/test/java (missing). General project directory, under the Java Resources Directory, there will also be src/main/test/resources this source folder. The missing will be deleted, re-created, and the missing directly created. Click the right button to delete and Add.

c) Modify the complete, effect such as

D) Next modify the configuration of the libraries, and the JRE uses version 1.7. Select JRE System library->edit to change the version.

e) Modify the order and export of the configuration, mainly to adjust the display order of the four directories, tune to their favorite order

f) then modify project facets to change Java to 1.7 first.

Dynamic Web module cannot be directly modified here to 3.0, you need to open a. Settings folder under the project directory, open the Org.eclipse.wst.common.project.facet.core.xml and make the following changes:

<installed facet= "Jst.web" version= "3.0"/>

Restart Eclipe to see that the changes are in effect.

4. Eclipse in Maven the configuration

A) Window->properties->maven, tick download repository index updates on startup

5. Simple Spring MVC the configuration

A) Open the Pom.xml file in the project and click on the Dependencies tab and click Add to add a new dependency

b) If you know the dependent group ID and artifact ID, you can directly fill in, if not clear, you can enter the keyword to query, or to http://search.maven.org site query

c) The dependencies that need to be added are: SPRING-WEBMVC, version 4.1.4. RELEASE. The complete Pom.xml file contains the following:

<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.springstudy</groupId> <artifactid>study</ artifactid> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name> Study Maven webapp</name> <url>http://maven.apache.org</url> <properties> < spring.version>4.1.4.release</spring.version> </properties> <dependencies> <dependency > <groupId>junit</groupId> <artifactId>junit</artifactId> &LT;VERSION&GT;3.8.1&L t;/version> <scope>test</scope> </dependency> <dependency> &LT;GROUPID&GT;ORG.SPR Ingframework</groupid> &LT;ARTIFACTID&GT;SPRING-WEBMVC</artifactId> <version>${spring.version}</version> </dependency> </dependencies> &lt ;build> <finalName>study</finalName> </build></project>

d) Open the Src/main/webapp/web-inf/web.xml file and finalize the changes as follows:

<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmln s= "Http://java.sun.com/xml/ns/javaee" xmlns:web= "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi: schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id= "study" V ersion= "2.5" > <display-name>archetype Created Web application</display-name> <descriptio                   N&GT;SPRINTMVC Environment Building </description> <!--loading Spring profiles--<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:/configs/spring                   -*.xml</param-value> </context-param> <!--Spring Monitor--<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> < /listener> <!--SprinG MVC configuration-<servlet> <servlet-name>Dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!- -Custom Spring MVC configuration file name and path-<init-param> <param-name>context Configlocation</param-name> <param-value>classpath:configs/spring-servlet.xml</p         Aram-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!--spring MVC request suffix--<servlet-mapping> <servle T-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-         Mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list&Gt;</web-app> 

e) In the Java resources/scr/main/resources directory, create the Configs folder to hold the configuration path declared in Web. xml

f) In the Java resources/scr/main/resources/configs directory, create the spring-servlet.xml with the following content:

<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" Xmlns:xs I= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:jee= "Http://www.springframework.org/schema/jee" xmlns: context= "Http://www.springframework.org/schema/context" xmlns:p= "http://www.springframework.org/schema/p" xmlns: Mvc= "Http://www.springframework.org/schema/mvc" xmlns:util= "Http://www.springframework.org/schema/util" xsi: schemalocation= "Http://www.springframework.org/schema/beans Http://www.springfra Mework.org/schema/beans/spring-beans-4.1.xsd Http://www.springframework. Org/schema/context http://www.springframework.org/schema/context/spring-                                                       Context-4.0.xsd Http://www.springframework.org/schema/jee Http://www.springframework.org/schema/jee/spring-jee-4.1.xsd http: Www.springframework.org/schema/mvc Http://www.springframework.org/sche                                                    Ma/mvc/spring-mvc-4.1.xsd Http://www.springframework.org/schema/util                  Http://www.springframework.org/schema/util/spring-util-4.1.xsd ">  <context:annotation-config/> <context:component-scan base-package= "Com.springstudy.controller" /> <mvc:annotation-driven/> <mvc:resources mapping= "/styles/**" location= "/styles/" /> <mvc:resources mapping= "/scripts/**" location= "/scripts/"/> <mvc:resources mapping= "/image s/** "location="/images/"/> <bean class=" org.springframework.web.servlet.view.InternalRe Sourceviewresolver ">                  <property name= "prefix" value= "/web-inf/views/"/> <property name= "suffix" va Lue= ". jsp"/> </bean></beans>

g) Create a controller package, in the Spring-servlet.xml file, <context:component-scan base-package="Com.springstudy.controller" /> has specified a path

h) in the Src/main/webapp/web-inf directory, create the views file, in the Spring-servlet.xml file, <property name=" prefix" value= "/w eb-inf/views/" /> has specified the view file path

i) Create the first controller file Hellocontroller.java, the complete file content is as follows:

Package Com.springstudy.controller; Import Org.springframework.stereotype.controller;import org.springframework.web.bind.annotation.RequestMapping; Import Org.springframework.web.servlet.ModelAndView; @Controllerpublic class Hellocontroller {          @RequestMapping ("/hello") public         Modelandview Hello () {                   Modelandview MV =new Modelandview ();                   Mv.addobject ("Spring", "Spring MVC");                   Mv.setviewname ("Hello");                   return mv;         }}

j) Add the src/main/webapp/web-inf/views/hello.jsp file with the following content:

<! DOCTYPE html>

6. publish the project to Tomcat

a) adding Tomcat 7 to eclipse

b) After Tomcat is added, double-click to set the settings for server locations in the Overview tab.

I. Select the Use Tomcat installation (takes control of Tomcat installation)

II. Change the contents of the Deploy path to: WebApps

III. Save

c) Right-click Tomcat,add and Remove ..., add study

d) Start Tomcat

e) Browser Open Http://localhost:8080/study/hello, Access success! Such as

Reproduced above to http://www.cnblogs.com/mybest/p/4265872.html

Have learned.

Learn the first day of Java

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.