Create Spring MVC Web program under Eclipse--non-MAVEN version

Source: Internet
Author: User

First, install Eclipse and Tomcat, where I downloaded the tomcat9.0 version 64-bit install-free: Address https://tomcat.apache.org/download-90.cgi

How do I start and close Tomcat without installing it? Double click on the mouse can be

Below, open eclipse: Navigation bar file->new->dynamic Web project, fill in project name, someone said, give the project name must be serious, like to give their children name, so as to uniquely identify! Here is the first spring project, named Springdemo, as shown in:

Click New Runtime to select your Tomcat, here I choose the latest version of 9.0:

Click Next to select the location of Tomcat: D:\Tomcat\apache-tomcat-9.0.1-windows-x64\apache-tomcat-9.0.1, JRE Select your installed JRE, click Finish

Configure as follows, click Finish to complete

Complete the following:

Here is the Spring jar package to download, here is a link, according to the link step by step download: http://www.cnblogs.com/leavescy/p/7657476.html

Put the jar package in the E:\javaEE\javaWorkplace\SpringDemo\WebContent\WEB-INF\lib (that is, your project directory) and restart Eclipse and you will see

Create related profiles and control files:

Xml:

<?XML version= "1.0" encoding= "UTF-8"?><Web-appversion= "3.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns= "Http://java.sun.com/xml/ns/javaee"xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"ID= "webapp_id" >        <Display-name>Springdemo</Display-name>        <!--Configure the Spring MVC dispatcher to intercept all requests -    <servlet>         <Servlet-name>Springmvc</Servlet-name>         <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class>         <Load-on-startup>1</Load-on-startup>    </servlet>    <servlet-mapping>         <Servlet-name>Springmvc</Servlet-name>         <Url-pattern>/</Url-pattern>     </servlet-mapping>          <Context-param>       <Param-name>Contextconfiglocation</Param-name>       <Param-value>/web-inf/applicationcontext.xml</Param-value>   </Context-param>    <Listener>      <Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class>   </Listener>       </Web-app>

Springmvc-servlet.xml

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns:p= "http://www.springframework.org/schema/p"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:mvc= "Http://www.springframework.org/schema/mvc"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-4.1.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/contex T/spring-context-4.1.xsd Http://www.springframework.org/schema/mvc Http://www.springframework.org/schema/mvc/sp Ring-mvc-4.1.xsd ">      <!--Turn on annotation mode driver -              <!--Sweep Package -          <Context:component-scanBase-package= "Com.springmvc.controller">      </Context:component-scan>        <Context:annotation-config/>               <Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver">         <!--specify the path where the page is stored -         < Propertyname= "prefix"value= "/web-inf/pages/"></ Property>         <!--Suffix of file -         < Propertyname= "suffix"value= ". jsp"></ Property>          </Bean>            </Beans>

Applicationcontext.xml:

 <?  xml version= "1.0" encoding= "UTF-8"  ?>  <  beans  xmlns  = "Http://www.springframework.org/schema/beans"   Xmlns:xsi  = "Http://www.w3.org/2001/XMLSchema-instance"   xsi:schemalocation  = "Http://www.springframework.org/schema/beans http://www.springframework.org/ Schema/beans/spring-beans.xsd " >  < !--  Empty  -->  </ beans  >  

Viewcontroller.java

 PackageCom.springmvc.controller;ImportOrg.springframework.stereotype.Controller;ImportOrg.springframework.ui.Model;Importorg.springframework.web.bind.annotation.RequestMapping; @Controller Public classViewcontroller {@RequestMapping (value= "/hello")      PublicString Hello (model model) {Model.addattribute ("Greeting", "Hello Spring MVC"); return"Index"; }}

INDEX.JSP:

<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>${greeting}</title></Head><Body>Congratulations, the Web project has been successfully built!</Body></HTML>

Right-click Project->run as->run on Server:

Indicates no error, enter in browser at this time: Http://localhost:8080/SpringDemo/hello

This means the project is successful!

Note: For the configuration of the free-install Tomcat, refer to: http://www.cnblogs.com/leavescy/p/7676262.html

The biggest difference between the Maven and non-MAVEN editions is how tomcat is enabled!

Create Spring MVC Web program under Eclipse--non-MAVEN version

Related Article

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.