"Springmvc" using MyEclipse to create a SPRINGMVC project "super-detailed tutorial"

Source: Internet
Author: User
Tags tomcat server

I've been using Eclipse to create a Web project, and sometimes there are problems when creating SPRINGMVC projects with idea and MyEclipse, and here's a record of this process, hoping to help those friends who need them. I am using MyEclipse2017 CI 3, similar version should be similar. As with other versions, you can find similar operations.

1. Create a new Web project

  

  

Then click Finish to complete the Web project creation.

2. Installing the Spring Framework

  

  

  

At this point, the project structure

  

3. Creating an XML file

  

  

The contents are as follows:

<?XML version= "1.0" encoding= "UTF-8"?><Web-appversion= "3.0"xmlns= "Http://java.sun.com/xml/ns/javaee"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_3_0.xsd">    <!--Configure SPRINGMVC -    <servlet>        <Servlet-name>Dispatcher</Servlet-name>        <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class>        <Init-param>              <Param-name>Contextconfiglocation</Param-name>              <Param-value>Classpath:dispatcher-servlet.xml</Param-value>          </Init-param>     </servlet>    <servlet-mapping>        <Servlet-name>Dispatcher</Servlet-name>        <!--listen to all requests -        <Url-pattern>/</Url-pattern>    </servlet-mapping></Web-app>

Then create a file named Dispatcher-servlet.xml (consistent with the file name specified above) in the SRC directory.

  

  

The contents are as follows:

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"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.xsd Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context-4.1.xsd Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/ Spring-mvc-4.1.xsd ">         <!--define the package to scan the controller -       <Context:component-scanBase-package= "Com.frank.springmvc.controller" />       <Mvc:default-servlet-handler/>        <!--Start note-driven SPRINGMVC feature -       <Mvc:annotation-driven/>       <!--Configure the View resolver resolution path -       <Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver"ID= "Internalresourceviewresolver">              <!--defining the View storage path -              < Propertyname= "prefix"value= "/web-inf/jsp/" />              <!--defining the View suffix -              < Propertyname= "suffix"value= ". jsp" />       </Bean></Beans>

Then create a folder named JSP under the Web-inf directory.

  

  

4. Define the Controller

Create a new package Com.frank.springmvc.controller (consistent with the package name specified in Dispatcher-servlet.xml)

  

  

Then create a controller class under the package named Hellospringmvc

  

  

The code is as follows:

 Package Com.frank.springmvc.controller; Import Org.springframework.stereotype.Controller; Import  publicclass  Hellospringmvc {    @RequestMapping ("/hello")        Public String Test () {          System.out.println ("test");          return "Hello";     }}

In this way, the request to the/hellospringmvc/hello path is shifted to the/web-inf/jsp/hello.jsp file

5. Create a JSP file

Create a hello.jsp file under the JSP folder

  

  

There will be some code in hello.jsp, here just as soon as possible to build SPRINGMVC run the project, without modification.

6. Deploy the project to the Tomcat server

  

  

  

Then start the server.

  

  

In the browser, type: Localhost:8080/springmvcdemo/hello

  

If the display is normal, our project deployment is successful.

"Springmvc" using MyEclipse to create a SPRINGMVC project "super-detailed tutorial"

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.