Spring MVC

  1. <servlet>  
  2.     <servlet-name>springmvc</servlet-name>  
  3.     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
  4.   <init-param>  
  5.     <param-name>contextConfigLocation</param-name>  
  6.     <param-value>classpath:springmvc.xml</param-value>  
  7.   </init-param>  
  8.     <load-on-startup>1</load-on-startup>  
  9.   </servlet>  
  10.   <servlet-mapping>  
  11.     <servlet-name>springmvc</servlet-name>  
  12.     <url-pattern>/</url-pattern>  
  13.   </servlet-mapping>  
  14.   <!--<servlet-mapping>-->  
  15.     <!--<servlet-name>default</servlet-name>-->  
  16.     <!--<url-pattern>.jpg</url-pattern>-->  
  17.   <!--</servlet-mapping>-->  
  18. </web-app>  
2.创建实体cn.happy.Controller下创建类 firstController
[java]  view plain  copy
  1. import org.springframework.web.servlet.ModelAndView;  
  2. import org.springframework.web.servlet.mvc.Controller;  
  3.   
  4. import javax.servlet.http.HttpServletRequest;  
  5. import javax.servlet.http.HttpServletResponse;  
  6.   
  7. /** 
  8.  * Created by Administrator on 2017/8/14. 
  9.  */  
  10. public class firstController implements Controller{  
  11.     public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {  
  12.     ModelAndView modelAndView=new ModelAndView();  
  13.         modelAndView.addObject("uname","y2165");  
  14.         modelAndView.setViewName("/index");  
  15.         return modelAndView;  
  16.     }  
  17. }  
3.配置小配置文件名字为springmvc.xml
[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.        xmlns:aop="http://www.springframework.org/schema/aop"  
  4.        xmlns:context="http://www.springframework.org/schema/context"  
  5.        xmlns:tx="http://www.springframework.org/schema/tx"  
  6.        xmlns:p="http://www.springframework.org/schema/p"  
  7.        xmlns:mvc="http://www.springframework.org/schema/mvc"  
  8.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  9.        xsi:schemaLocation="  
  10.          http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd  
  11.         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
  12.         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd  
  13.         http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context.xsd  
  14.         http://www.springframework.org/schema/tx  http://www.springframework.org/schema/tx/spring-tx.xsd  
  15. ">  
  16.   
  17.   
  18.     <!--<mvc:default-servlet-handler/>-->  
  19.     <mvc:resources    mapping="/img/**" location="/img/"></mvc:resources>  
  20.   
  21.     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
  22.         <property name="prefix" value="WEB-INF"></property>  
  23.         <property name="suffix" value=".jsp"></property>  
  24.     </bean>  
  25.   
  26.     <bean id="/happy.do" class="cn.happy.Controller.firstController"></bean>  
  27.   
  28. </beans>  
4.创建index.jsp文件

[html]  view plain  copy
  1. <%--  
  2.   Created by IntelliJ IDEA.  
  3.   User: Administrator  
  4.   Date: 2017/8/14  
  5.   Time: 9:52  
  6.   To change this template use File | Settings | File Templates.  
  7. --%>  
  8. <%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>  
  9. <html>  
  10. <head>  
  11.     <title>title</title>  
  12. </head>  
  13. <body>  
  14.   
  15. <h2>SpringMVC,${uname}</h2>  
  16. <img src="img/1.jpg">  
  17. </body>  
  18. </html>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值