當(dāng)前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
SpringMVC入门案例
生活随笔
收集整理的這篇文章主要介紹了
SpringMVC入门案例
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
web.xml
<?xml version="1.0" encoding="UTF-8"?> <!--suppress ALL --> <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_3_0.xsd" id="WebApp_ID" version="3.0"><display-name>1.SpringMVC_helloworld</display-name><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list><!-- The front controller of this Spring Web application,responsible for handling all application requests --><servlet><servlet-name>springDispatcherServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><!-- contextConfigLocation:指定SpringMVC配置文件位置 --><param-name>contextConfigLocation</param-name><param-value>classpath:springmvc.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><!-- Map all requests to the DispatcherServlet for handling --><servlet-mapping><servlet-name>springDispatcherServlet</servlet-name><url-pattern>/</url-pattern></servlet-mapping></web-app>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> <a href="hello">helloworld</a> </body> </html>success.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> <h1>成功!</h1></body> </html>springmvc.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"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"><!-- 掃描所有組件 --><context:component-scan base-package="com.atguigu"></context:component-scan></beans>MyFirstController.java
package com.atguigu.controller;import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping;@Controller public class MyFirstController {@RequestMapping("/hello")public String myfirstRequest(){System.out.println("請求收到了....正在處理中");return "/WEB-INF/pages/success.jsp";}} 《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的SpringMVC入门案例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 全局配置文件:mybatis-confi
- 下一篇: RequestMapping || @R