Spring MVC Series: (7) SPRINGMVC QuickStart (annotated version)

Source: Internet
Author: User


1. Introduction of JAR Package

Spring-core

Commons-logging-1.2.jar

Spring-beans-3.2.5.release.jar

Spring-context-3.2.5.release.jar

Spring-core-3.2.5.release.jar

Spring-expression-3.2.5.release.jar

Spring-web Spring-web-3.2.5.release.jar
Spring-webmvc Spring-webmvc-3.2.5.release.jar


2. Configuration

Xml

<?xml version= "1.0"  encoding= "UTF-8"? ><web-app 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_2_5.xsd " id=" WebApp_ID "  version= "2.5" >  <display-name>springmvc02</display-name>  < welcome-file-list>    <welcome-file>index.jsp</welcome-file>   </welcome-file-list>    <!--  Register SPRINGMVC core Controllers  -->  < Servlet>  <servlet-name>springmvc</servlet-name>  <servlet-class> org.springframework.web.servlet.dispatcherservlet</servlet-class>  <init-param>   <param-name>contextconfiglocation</param-name>  <param-value>classpath: Springmvc.xml</param-value>  </init-paraM>  </servlet>  <servlet-mapping>  <servlet-name>springmvc </servlet-name>  <url-pattern>*.action</url-pattern>  </ servlet-mapping>    <!--  Register Spring's encoding filter in Spring-web's jar package  -->   <filter>  <filter-name>CharacterEncodingFilter</filter-name>  < filter-class>org.springframework.web.filter.characterencodingfilter</filter-class>  < Init-param>  <param-name>encoding</param-name>  <param-value>utf-8 </param-value>  </init-param>  </filter>  <filter-mapping >  <filter-name>characterencodingfilter</filter-name>  <url-pattern>/ *</url-pattern>  </filter-mapping>  </web-app>


Springmvc.xml

<?xml version= "1.0"  encoding= "UTF-8"? ><beans xmlns= "http://www.springframework.org/ Schema/beans "    xmlns:mvc=" Http://www.springframework.org/schema/mvc "     xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"     xmlns:context= "http// Www.springframework.org/schema/context "    xsi:schemalocation="          http://www.springframework.org/schema/beans         http://www.springframework.org/schema/beans/spring-beans.xsd         http://www.springframework.org/schema/mvc        http:// www.springframework.org/schema/mvc/spring-mvc.xsd        http:// www.springframework.org/schema/context        http:// Www.springframework.org/schema/context/spring-context.xsd">    <!-- <import resource=" Com/rk/config/spring-test.xml "/>      -->    <!-- action Controller  -->     <context:component-scan base-package= "Com.rk.action" ></context:component-scan>         <!--  Annotation-based mapper (optional)  -->    < bean class= "Org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>           <!--  Annotation-based adapters (optional)  -->     <bean class= "Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>           <!--  View resolver (optional)  -->     <bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver"/></ Beans>


3. Create Helloworldaction Controller

Helloworldaction.java

Package Com.rk.action;import Org.springframework.stereotype.controller;import Org.springframework.ui.model;import org.springframework.web.bind.annotation.RequestMapping; @Controllerpublic class Helloworldaction {@RequestMapping (    Value= "/test") public String test (model model) throws exception{System.out.println ("Helloworldaction.test ()"); Model.addattribute ("message", "This is my second SPRINGMVC app!")    "); return "/index.jsp";}}


4. JSP page

Modify the index.jsp page under webroot/

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >


5. Deployment Access


Access Address:

Http://127.0.0.1:8080/springmvc02/test.action


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/87/BB/wKioL1fgV7-RdToVAAA6Y-GUf9w724.png "title=" 001. PNG "alt=" Wkiol1fgv7-rdtovaaa6y-guf9w724.png "/>




Spring MVC Series: (7) SPRINGMVC QuickStart (annotated version)

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.