springmvc 配置文件

来源:互联网 发布:淘宝网首页戴丝玉 编辑:程序博客网 时间:2024/05/16 12:08

1、在同级目录下。默认就ok


<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">  <display-name>springMVC1</display-name>  <welcome-file-list>    <welcome-file>index.html</welcome-file>    <welcome-file>index.htm</welcome-file>    <welcome-file>index.jsp</welcome-file>    <welcome-file>default.html</welcome-file>    <welcome-file>default.htm</welcome-file>    <welcome-file>default.jsp</welcome-file>  </welcome-file-list>    <servlet>  <servlet-name>springMVC</servlet-name> <!-- 这个名字就是配置文件 springMVC-servlet.xml -->  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  <!-- <init-param>  <param-name>contextConfigLocation</param-name>  <param-value>classpath*:config/spring-servlet.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></web-app>  

另外一个目录下

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"   xmlns:context="http://www.springframework.org/schema/context"   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/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.xsd        http://www.springframework.org/schema/mvc        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">                  <bean name="/test1/helloworld" class="com.tgb.web.controller.HelloWorldController" />        <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">        <property name="prefix" value="/"></property>        <property name="suffix" value=".jsp"></property>    </bean> </beans>

src目录下

package com.tgb.web.controller;import java.util.HashMap;import java.util.Map;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.web.servlet.ModelAndView;import org.springframework.web.servlet.mvc.Controller;public class HelloWorldController implements Controller {@Overridepublic ModelAndView handleRequest(HttpServletRequest arg0,HttpServletResponse arg1) throws Exception {System.out.println("-------hello tgb-----");String hello = "lsh hello 提高班";Map<String,Object> map = new HashMap<String,Object>();map.put("map1", "提高班1");map.put("map2", "提高班2");map.put("map3", "提高班3");//返回string数据//return new ModelAndView("/welcome","result",hello);//下面是返回map数据return new ModelAndView("/welcome","map",map);}}




http://localhost:8080/springquanbu/test1/helloworld

0 0
原创粉丝点击