1.下载spring 的jar包。


spring mvc 基础配置
 2.在web.xml里配置DispatcherServlet

<servlet>
   <servlet-name>sampleBankingServlet</servlet-name>  
   <servlet-class>
      org.springframework.web.servlet.DispatcherServlet
   </servlet-class>
   <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>  
        <servlet-name>sampleBankingServlet</servlet-name>  
        <url-pattern>/app/*</url-pattern>  
    </servlet-mapping> 

 3.sampleBankingServlet-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:p="http://www.springframework.org/schema/p"  
    xmlns:context="http://www.springframework.org/schema/context"  
    xmlns:mvc="http://www.springframework.org/schema/mvc"  
    xsi:schemaLocation="  
    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  
    http://www.springframework.org/schema/mvc  
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd  
    ">  
    <!-- Enable annotation driven controllers, validation etc... -->  
    <context:component-scan base-package="cn.spring" />  
  
    <mvc:annotation-driven />  
    <bean id="viewResolver"  class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
        <property name="prefix" value="/"/>  
        <property name="suffix" value=".jsp"/>  
    </bean>  
  
</beans>  

 4.前台提交设置:

<?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:context="http://www.springframework.org/schema/context"  
    xmlns:mvc="http://www.springframework.org/schema/mvc"  
    xsi:schemaLocation="  
    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  
    http://www.springframework.org/schema/mvc  
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd  
    ">  
    <!-- Enable annotation driven controllers, validation etc... -->  
    <context:component-scan base-package="cn.spring" />  
  
    <mvc:annotation-driven />  
    <bean id="viewResolver"  class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
        <property name="prefix" value="/"/>  
        <property name="suffix" value=".jsp"/>  
    </bean>  
  
</beans>  

 5.后台controller编写

package cn.spring;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class IndexController {
	@RequestMapping("index")//拦截"/app/index"请求  
    private String index(){  
        return "hello";//跳转到"hello.jsp"页面  
    }  
}
 

相关文章:

  • 2021-08-03
  • 2021-06-17
  • 2021-04-06
  • 2022-12-23
  • 2022-02-17
猜你喜欢
  • 2021-11-15
  • 2022-12-23
  • 2021-12-03
  • 2021-06-11
  • 2021-07-08
  • 2022-12-23
  • 2021-12-25
相关资源
相似解决方案