springmvc配置

第一步导入jar包:我这里是导入3.05这个版本有点低够用进行


第二部 配置web.xml文件:



省去红色中要写入自动加载

配置spring


在WEB-INF下新建config文件 新建applicationContext.xml文件


第二步:我用的eclipse 这里命名 test 这里就需要在WEB-INF建一个test-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"
       xmlns:p="http://www.springframework.org/schema/p"  
  xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">





     <!-- 启用spring mvc 注解 -->
    <context:annotation-config />
    <context:component-scan base-package="com.controller"></context:component-scan>  


<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 请求映射 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"   
        p:prefix="/WEB-INF/page/" p:suffix=".jsp">  
    </bean>  




</beans>

第三步中java类中加入标签

package com.controller;


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


@Controller


@RequestMapping("/brt")
public class IndexController {
@RequestMapping(value="/login",method = RequestMethod.GET)
public String goIndex(){
System.out.println("进入");
return "index";
}

}

第四步

启动tomcat 后输入

http://localhost:8080/test/brt/login 简单配置springMVC





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值