springMVC环境配置
2015-08-05 09:56
387 查看
springMVC环境主要需要spring的Core Libraries和Web Libraries,使用myeclipse可以直接添加这两个包。注意:使用官方的lib时需要另外自己加入com.springsource.org.apache.commons.logging-1.1.1.jar,不然会报错。
spring-mvc.xml
applicationContext.xml
web.xml
Demo.java
主要是这三个配置文件的编写,然后将jsp文件放在对应的文件夹。最后访问路径是:http://服务器地址:端口/项目名/类的RequestMapping/方法的RequestMapping
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:tx="http://www.springframework.org/schema/tx" 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.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"> <!-- 激活@Required @Autowired @Resource等标签 --> <context:annotation-config/> <!-- DispatcherServlet上下文,指定扫描Controller标注的类 --> <context:component-scan base-package="com.demo"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <!-- 默认的注解映射的支持 --> <mvc:annotation-driven /> <!-- 指定view的目录以及文件的后缀 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> </beans>
applicationContext.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:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"> </beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>springMVC</display-name> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>mvc-dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- DispatcherServlet对应的上下文配置 --> <!-- 下面指定加载的 mvc-dispatcher-servlet.xml的位置--> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/configs/spring-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvc-dispatcher</servlet-name> <!-- 配置拦截请求的类型 --> <url-pattern>/</url-pattern> </servlet-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> </web-app>
Demo.java
package com.demo; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping("/hello") public class Demo { @RequestMapping("/one") public String hello(){ return "hello"; } }
主要是这三个配置文件的编写,然后将jsp文件放在对应的文件夹。最后访问路径是:http://服务器地址:端口/项目名/类的RequestMapping/方法的RequestMapping
相关文章推荐
- 杭电ACM2041java做法
- 如何在 Java 中正确使用 wait, notify 和 notifyAll
- Leetcode-204(Java) Count Primes
- myeclipse&eclipse的项目源码部署到哪里去了?
- Gradle在大型Java项目上的应用
- java.lang.IllegalArgumentException: Line argument must contain a key and a value
- Java NIO框架Netty教程 (五) 字符串消息收发
- 深入解析Java中的JDBC事务
- ArrayList中重复元素处理方法.[Java]
- JDK动态代理与Cglib库
- struts 2 的原理 更加详细
- Java NIO框架Netty教程(二) – 白话概念
- Java NIO框架Netty教程(一) – Hello Netty
- spring整合消息队列rabbitmq
- 斜堆 之 Java的实现
- java命令执行jar包的方式
- Spring MVC
- Spring注解学习(一)-构建简单Web应用
- Leetcode-210(Java) Course Schedule II
- 淘宝JAVA中间件Diamond详解(1)-简介&快速使用