springMVC框架的搭建最简单项目(没有数据库的配置)
2015-08-27 10:24
881 查看
新建一个web项目
将SpringMVC需要的导入到项目中
先配置web.xml中内容。其中需要配置的内容有:
最简单的只需要注册springMVC就行了,其配置如下
4.因为在web.xml中已经指明springMVC的配置文件位置,在对应目录下新建对应文件名的配置文件。
5.配置springMVC文件,需要配置的内容有:
开启注解和自动注入
指明注解的action的位置
指明视图的文件类型和文件所在位子
如下所示:
6.最后编写action文件,注意action文件的位子一定要在springMVC配置文件中所配置的位子
7.在配置的视图文件夹下新建login.jsp
8.使用tomcat发布下
9.在浏览器输入地址测试
将SpringMVC需要的导入到项目中
先配置web.xml中内容。其中需要配置的内容有:
最简单的只需要注册springMVC就行了,其配置如下
<?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_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>SpringMVC</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- 配置springMVC --> <servlet> <servlet-name>SpringMvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 指明content位置 --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/springServlet.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>
4.因为在web.xml中已经指明springMVC的配置文件位置,在对应目录下新建对应文件名的配置文件。
5.配置springMVC文件,需要配置的内容有:
开启注解和自动注入
指明注解的action的位置
指明视图的文件类型和文件所在位子
如下所示:
<?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:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd" default-autowire="byName"> <mvc:annotation-driven/> <!-- 设置使用注解的类所在的jar包 --> <context:component-scan base-package="team.action" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/jsp/"/> <property name="suffix" value=".jsp"/> </bean> </beans>
6.最后编写action文件,注意action文件的位子一定要在springMVC配置文件中所配置的位子
package team.action; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping(value="/user") public class User { @RequestMapping(value="/login") public String tologin(){ return "login"; } }
7.在配置的视图文件夹下新建login.jsp
8.使用tomcat发布下
9.在浏览器输入地址测试
相关文章推荐
- [转自wangpeng047]Eclipse使用入门教程
- java - mysql连接
- Java常用集合类
- javax.naming.NameNotFoundException
- xsd 生成 java类
- SpringMVC返回值的几种方式
- Android Eclipse Ant 编译打包
- Java如何跳出2层for循环
- eclipse maven插件安装及配置
- myeclipse的maven工程找不到java基本类, 报javax.servlet,servletActionContext不存在
- spring-hessian代理、服务那点事
- eclipse maven plugin 插件 安装 和 配置
- java 接口和抽象类
- 我的第一个java定时器
- Spring整合hibernate:3、使用XML进行声明式的事务管理
- java实现定时任务3种方法
- java获得文件全路径中关于路径分隔符的使用
- Java RMI之HelloWorld篇
- Android Eclipse安装Ant插件
- Eclipse背景颜色修改