springMVC之helloworld
使用springMVC创建web项目,我会使用MAVEN构建工具,因为它可以使我们不再关注会不会缺少什么jar包,可以将我们的精力完全用在编码上
默认你的环境下已经配置好了maven的环境
1,我们在eclipse下面创建maven项目

点击next

点击next

finish

选择项目,单击右键,选择build path




项目就创建好了

项目创建成功之后,首先,我们下载springMVC运行所依赖的jar包

然后配置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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd ">
<!-- 扫描找到了ItemsController3 -->
<context:component-scan base-package="controller"></context:component-scan>
<!-- 视图解析器-->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 配置jsp路径的后缀 -->
<property name="suffix" value=".jsp"/>
</bean>
</beans>
spring-mvc.xml 配置好之后 在web.xml文件里注册dispatcherServlet

然后创建controller


浙公网安备 33010602011771号