springmvc搭建(注解)
web.xml添加内容:
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:com/acc/config/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>spring-mvc.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/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">
<!-- 激活annotation功能 -->
<context:annotation-config />
<!-- 启动 annotation事务 -->
<mvc:annotation-driven />
<!-- 导入数据源配置文件 -->
<!-- 启动 IOC注解,扫描指定package下所有注解,并把注解注册为Spring Beans,事务处理-->
<!--<context:component-scan base-package="com.acc.service.**"/>-->
<context:component-scan base-package="com.acc.controller.**"/>
<!-- <context:component-scan base-package="com.acc.entity.**"/> -->
<!-- 这样根目录下面的resource的文件(.css,.js等)就不会被spring的DispatchServlet进行过滤-->
<mvc:resources location="/resources/" mapping="/resources/**"/>
<!-- 声明视图解析器. <property name="prefix" value="/WEB-INF/view/" /> -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>Login.java内容:
package com.acc.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class Login {
@RequestMapping(value = "/login")
public String login(){
return "123";
}
}注:123为WEB-INF/view/123.jsp,jsp内容随意
访问路径:http://localhost:8080/accumulation/login.html
相关推荐
JudeJoo 2020-08-21
meleto 2020-08-15
neweastsun 2020-05-04
牧场SZShepherd 2020-02-21
凯哥Java 2020-02-16
itjavashuai 2020-08-15
zhongliwen 2020-07-05
haidaoxianzi 2020-07-04
小鱿鱼 2020-06-26
haidaoxianzi 2020-06-17
MicroBoy 2020-06-17
牧场SZShepherd 2020-06-17
neweastsun 2020-06-16
haidaoxianzi 2020-06-14
zhongliwen 2020-06-13
@RequestBody注解实现接收http请求的json数据,将json数据转换为java对象进行绑定。加上@ResponseBody注解,就不会走视图解析器,不会返回页面,目前返回的json数据。
DumbbellYang 2020-06-13
csuzxm000 2020-06-09
haidaoxianzi 2020-06-03