码迷,mamicode.com
首页 > 编程语言 > 详细

springmvc 入门级教程

时间:2014-12-04 13:57:22      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   ar   color   sp   java   

1、先看下目录结构

bubuko.com,布布扣

2、引用所需的jar文件

 

3、web.xml 配置如下

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"  
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee       
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">       
<servlet>              
<servlet-name>springmvc</servlet-name>              
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>      
 </servlet>             
 <servlet-mapping>              
 <servlet-name>springmvc</servlet-name>             
  <!-- 监听所有请求 -->              
  <url-pattern>/</url-pattern>     
 </servlet-mapping>
</web-app>

4、springmvc-servlet.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"       
xmlns:mvc="http://www.springframework.org/schema/mvc"       
xsi:schemaLocation="http://www.springframework.org/schema/mvc         
     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd              
     http://www.springframework.org/schema/beans              
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd              
     http://www.springframework.org/schema/context              
     http://www.springframework.org/schema/context/spring-context-3.0.xsd">       
     <!-- 扫描所有的 controller -->       
     <context:component-scan base-package="controller" />       
     <!-- 启动注解驱动 SpringMVC 功能 -->       
     <mvc:annotation-driven />       
     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
     <property name="prefix" value="/views/" />             
      <property name="suffix" value=".jsp" />
      </bean>
 </beans>

5、根目录下新寻views文件夹在里面新建home子文件夹然后再新建 index.jsp(普通页面)
index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP ‘index.jsp‘ starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>
  
  <body>
    This is my JSP page. <br>
  </body>
</html>

 

springmvc 入门级教程

标签:des   style   blog   http   io   ar   color   sp   java   

原文地址:http://www.cnblogs.com/lvlv/p/4142625.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!