基于XML配置的springMVC小案例
来源:互联网 发布:aigowifidisk mac 编辑:程序博客网 时间:2024/04/29 08:07
基于XML配置的springMVC小案例
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:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:util="http://www.springframework.org/schema/util"xmlns:jpa="http://www.springframework.org/schema/data/jpa"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsdhttp://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsdhttp://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsdhttp://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd"><bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/hello.do">helloController</prop> </props> </property> </bean> <bean id="helloController" class="controller.HelloController"/><!-- 配置视图解析器 --><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/"/> <property name="suffix" value=".jsp"/> </bean> </beans>
HelloController.java
package controller;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 HelloController implements Controller{public ModelAndView handleRequest(HttpServletRequest req,HttpServletResponse res) throws Exception {System.out.println("HelloController处理请求...");//hello是视图名,ViewResolver会将//视图名解析成真正的页面的名称,比如//解析成hello.jsp。return new ModelAndView("hello");}}
web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <!-- DispatcherServlet的初始化方法 在执行时,会启动spring容器。 --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup></servlet><servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>*.do</url-pattern></servlet-mapping> </web-app>
hello.jsp
<h1>Hello,SpringMVC!</h1>
0 0
- 基于XML配置的springMVC小案例
- 基于注解配置的springMVC小案例
- Springmvc案例1----基于spring2.5的采用xml配置
- Mybatis基于xml配置的入门案例
- 基于xml配置springmvc
- 基于xml的springmvc配置例子
- 基于XML配置的SpringMVC项目示例
- springmvc基于xml文件的配置方式
- 六、初学SpringMVC+Mybatis之SpringMVC基于XML的配置
- PHP:基于XML的在线小词典案例
- web.xml配置,基于SpringMVC
- 基于xml的SpringMVC
- Spring 基于XML配置的IOC入门案例
- Spring 基于XML配置的AOP入门案例
- 8.javaweb之基于XML配置的Hello World案例
- springMVC 基于XML的配置-解决跨域问题
- 基于springmvc实现上传下载的案例
- springmvc整合redis的小案例
- 在Android使用AIDL实现IPC机制
- redis 持久化与备份策略
- 发邮件
- C++练手之计算老妈的工作时间段
- Leetcode: 328. Odd Even Linked List(JAVA)
- 基于XML配置的springMVC小案例
- 基于linux的正则表达式以及工具的使用
- ios开发之多线程NSThread
- 4407: 于神之怒加强版 莫比乌斯反演+线性筛积性函数
- iOS-App installation failed原因及解决方法
- Java 9终于要包含Jigsaw项目了
- 使用Apriori算法进行关联分析
- 解压任意多层的文件夹 Java代码实现
- 文本分类入门(十)特征选择算法之开方检验