- <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>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>springmvc</servlet-name>
- <url-pattern>/</url-pattern>
- </servlet-mapping>
- <!--<servlet-mapping>-->
- <!--<servlet-name>default</servlet-name>-->
- <!--<url-pattern>.jpg</url-pattern>-->
- <!--</servlet-mapping>-->
- </web-app>
- import org.springframework.web.servlet.ModelAndView;
- import org.springframework.web.servlet.mvc.Controller;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- /**
- * Created by Administrator on 2017/8/14.
- */
- public class firstController implements Controller{
- public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
- ModelAndView modelAndView=new ModelAndView();
- modelAndView.addObject("uname","y2165");
- modelAndView.setViewName("/index");
- return modelAndView;
- }
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:p="http://www.springframework.org/schema/p"
- xmlns:mvc="http://www.springframework.org/schema/mvc"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="
- http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
- ">
- <!--<mvc:default-servlet-handler/>-->
- <mvc:resources mapping="/img/**" location="/img/"></mvc:resources>
- <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
- <property name="prefix" value="WEB-INF"></property>
- <property name="suffix" value=".jsp"></property>
- </bean>
- <bean id="/happy.do" class="cn.happy.Controller.firstController"></bean>
- </beans>
- <%--
- Created by IntelliJ IDEA.
- User: Administrator
- Date: 2017/8/14
- Time: 9:52
- To change this template use File | Settings | File Templates.
- --%>
- <%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
- <html>
- <head>
- <title>title</title>
- </head>
- <body>
- <h2>SpringMVC,${uname}</h2>
- <img src="img/1.jpg">
- </body>
- </html>