首页 > 代码库 > springmvc

springmvc

                                           这种比较原始不推荐*******************************************  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">  <display-name></display-name>      <welcome-file-list>    <welcome-file>index.jsp</welcome-file>  </welcome-file-list>    <servlet>          <servlet-name>welcome</servlet-name>          <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>         <load-on-startup>1</load-on-startup>         <!--当spring的配置文件在web-inf的目录下 -->         <!-- <init-param>             <param-name>contextConfigLocation</param-name>             <param-value>classpath:welcome-servlet.xml</param-value>         </init-param> -->  </servlet>  <servlet-mapping>          <servlet-name>welcome</servlet-name>          <url-pattern>/</url-pattern>  </servlet-mapping></web-app>*************************************  welcome-servliet.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:p="http://www.springframework.org/schema/p"    xmlns:tx="http://www.springframework.org/schema/tx"    xmlns:aop="http://www.springframework.org/schema/aop"    xsi:schemaLocation="http://www.springframework.org/schema/beans    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd    http://www.springframework.org/schema/tx    http://www.springframework.org/schema/tx/spring-tx-3.1.xsd    http://www.springframework.org/schema/aop    http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">    <--默认是beanNameUrlHandlerMapping-->    <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>    <!--通过bean的name完成url的映射  -->    <bean name="/welcome.html" class="com.gym.controller.Welcome"/>    <!-- 视图解析器 -->    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">        <property name="prefix" value="/WEB-INF/jsp/"></property>        <property name="suffix" value=".jsp"></property>    </bean>    </beans>***************************   /129springMVC/src/com/gym/controller/Welcome    ****************package com.gym.controller;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.web.servlet.ModelAndView;import org.springframework.web.servlet.mvc.AbstractController;public class Welcome extends AbstractController {    @Override    protected ModelAndView handleRequestInternal(HttpServletRequest arg0,            HttpServletResponse arg1) throws Exception {        System.out.println("welcome,springMVC");        return new ModelAndView("welcome");    }}*******************************************  WEB-INE/jsp/welcome.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 ‘welcome.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="http://www.mamicode.com/styles.css">    -->  </head>    <body>        <h1>welcome,springmvc</h1>  </body></html>*********************************************************************************************

 

springmvc