簡單的spring mvc執行個體

來源:互聯網
上載者:User

標籤:nbsp   www.   war   config   index   get   lis   nap   enc   

簡單的springmvc執行個體

pom.xml

<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.muyang</groupId>  <artifactId>gu2</artifactId>  <packaging>war</packaging>  <version>0.0.1-SNAPSHOT</version>  <name>gu2 Maven Webapp</name>  <url>http://maven.apache.org</url>    <properties>    <spring.version>4.3.5.RELEASE</spring.version>  </properties>    <dependencies>         <!-- spring模組庫 -->    <dependency>        <groupId>org.springframework</groupId>        <artifactId>spring-beans</artifactId>        <version>${spring.version}</version>    </dependency>    <dependency>        <groupId>org.springframework</groupId>        <artifactId>spring-web</artifactId>        <version>${spring.version}</version>    </dependency>    <dependency>        <groupId>org.springframework</groupId>        <artifactId>spring-webmvc</artifactId>        <version>${spring.version}</version>    </dependency>     <!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->    <!-- transaction事務 -->    <dependency>        <groupId>org.springframework</groupId>        <artifactId>spring-tx</artifactId>        <version>${spring.version}</version>    </dependency>                   <!-- Servlet dependencies -->    <!-- servlet(HttpServletRequest,HttpServletResponse) -->     <dependency>        <groupId>javax.servlet</groupId>        <artifactId>javax.servlet-api</artifactId>        <version>3.1.0</version>    </dependency>         <!-- Jstl for jsp page -->    <!-- https://mvnrepository.com/artifact/jstl/jstl -->    <dependency>        <groupId>jstl</groupId>        <artifactId>jstl</artifactId>        <version>1.2</version>    </dependency>         <!-- JSP API -->    <!-- http://mvnrepository.com/artifact/javax.servlet.jsp/jsp-api -->    <dependency>         <groupId>javax.servlet.jsp</groupId>         <artifactId>jsp-api</artifactId>         <version>2.2</version>         <scope>provided</scope>     </dependency>                        </dependencies>          <build>    <finalName>gu2</finalName>  </build></project>

  

web.xml

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" ><web-app>  <display-name>Archetype Created Web Application</display-name>    <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>    <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>          </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:mvc="http://www.springframework.org/schema/mvc"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"> <!-- 掃描包,自動引入bean  --><context:component-scan base-package="springmvc"/> <!-- 視圖 --><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">    <property name="prefix">        <value>/WEB-INF/views/</value>    </property>    <property name="suffix">        <value>.jsp</value>    </property></bean> </beans>

  

applicationContext.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:mvc="http://www.springframework.org/schema/mvc"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">    </beans>

  

HelloController.java

package springmvc.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;@Controllerpublic class HelloController {@RequestMapping(value="/hello", method=RequestMethod.GET)    public String hello()    {              return "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><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Insert title here</title></head><body>ghfgdfg</body></html>

  

 

簡單的spring mvc執行個體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.