SpringMVC_HelloWorld_02, springmvchelloworld

Source: Internet
Author: User

SpringMVC_HelloWorld_02, springmvchelloworld

Implement a simple HelloWorld through annotation.

1. Create a project

Same as SpringMVC_HelloWorld_01

Ii. Configuration File 1. Configure web. xml

Same as SpringMVC_HelloWorld_01

2. Configure springmvc-servlet.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" 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 h Ttp: // www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd "> <! -- Configure a custom scan package --> <context: component-scan base-package = "com. zhy. controllers"> </context: component-scan> <! -- Configure the view parser --> <bean class = "org. springframework. web. servlet. view. InternalResourceViewResolver"> <! -- Configure prefix --> <property name = "prefix" value = "/WEB-INF/views/"> </property> <! -- Configure the suffix --> <property name = "suffix" value = ". jsp"> </property> </bean> </beans>
3. Compile the Controller
Package com. zhy. controllers; import org. springframework. stereotype. controller; import org. springframework. web. bind. annotation. requestMapping; @ Controllerpublic class HelloWorldController {/** get the actual physical view through ViewResolver * parsing rules of the view Parser: prefix + returnvalue + suffix * combined with this instance, the physical view parsed by the view parser is:/WEB-INF/views/helloworld. jsp **/@ RequestMapping ("/mvc") public String hello () {System. out. println ("call controller"); return "helloworld ";}}
4. Create a jsp page

Same as SpringMVC_HelloWorld_01

Iv. Run

Same as SpringMVC_HelloWorld_01

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.