SpringMvc基础基础最基础
来源:互联网 发布:快消行业数据分析 编辑:程序博客网 时间:2024/04/26 01:26
配置步骤:
1.首先我们需要配置web.xml
<servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!--<servlet-mapping>--> <!--<servlet-name>default</servlet-name>--> <!--<url-pattern>.jpg</url-pattern>--> <!--</servlet-mapping>--></web-app>2.创建实体cn.happy.Controller下创建类 firstController
import org.springframework.web.servlet.ModelAndView;import org.springframework.web.servlet.mvc.Controller;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;/** * Created by Administrator on 2017/8/14. */public class firstController implements Controller{ public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { ModelAndView modelAndView=new ModelAndView(); modelAndView.addObject("uname","y2165"); modelAndView.setViewName("/index"); return modelAndView; }}3.配置小配置文件名字为springmvc.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!--<mvc:default-servlet-handler/>--> <mvc:resources mapping="/img/**" location="/img/"></mvc:resources> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="WEB-INF"></property> <property name="suffix" value=".jsp"></property> </bean> <bean id="/happy.do" class="cn.happy.Controller.firstController"></bean></beans>4.创建index.jsp文件
<%-- Created by IntelliJ IDEA. User: Administrator Date: 2017/8/14 Time: 9:52 To change this template use File | Settings | File Templates.--%><%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %><html><head> <title>title</title></head><body><h2>SpringMVC,${uname}</h2><img src="img/1.jpg"></body></html>
阅读全文
0 0
- SpringMvc基础基础最基础
- SpringMVC最基础配置
- SpringMVC最基础配置
- springMVC基础
- springMVC基础
- springMVC基础
- SpringMVC基础
- springMVC基础
- springmvc 基础
- SpringMVC 基础
- springMVC基础
- SpringMVC基础
- SpringMVC基础
- springMVC基础
- springmvc基础
- SpringMVC基础
- springmvc基础
- springMVC基础
- linux下执行bin不加./怎么直接运行
- mysql(四/3)表的操作
- Nginx多方位优化策略
- js写计算器实现加减乘除效果
- 欢迎使用CSDN-markdown编辑器
- SpringMvc基础基础最基础
- TensorFlow入门教程:1:安装和第一个例子程序
- window下cmd文件和文件夹的相关命令
- Java中的接口
- JAVA类型转换
- P1605 迷宫
- jquery_01_1
- thinkphp修改配置文件配置项
- iOS第三方库汇总