开发工具:eclipse
jdk:1.7
lib:
spring-aop:包含spring的Aop特性所需类
spring-beans:spring基础包,包含访问配置文件、创建和管理bean,依赖注入操作相关的类
spring-context:spring核心扩展包,可以找到使用Spring ApplicationContext特性时所需的全部类,JDNI所需的全部类,UI方面的用来与模板(Templating)引擎如Velocity、FreeMarker、JasperReports集成的类,以及校验Validation方面的相关类。
spring-core:sping框架的核心工具包
spring-web:spring框架的开发web应用所需包
spring-webmvc:包含Spring MVC框架相关的所有类。
commons-logging:高层的日志框架,本身没有实现真正的日志能力,它依赖其他的日志系统如log4j或者java本身的java.util.logging。

首先在eclipse建立一个Dynamic Web Project项目
1.加入jar包
2.在配置web.xml文件中配置DispatcherServlet
<servlet>
<servlet-name>springDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<!– Map all requests to the DispatcherServlet for handling –>
<servlet-mapping>
<servlet-name>springDispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
3.加入SpringMvc配置文件
<?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”
xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd”>
<!– 配置扫描包 测试项目设为“*” 表示扫描所有,真实项目不这样写–>
<context:component-scan base-package=”*”></context:component-scan>
<!– 视图解析器:逻辑视图:物理视图 –>
<bean class=”org.springframework.web.servlet.view.InternalResourceViewResolver”>
<property name=”prefix” value=”/”></property>
<property name=”suffix” value=”.jsp”></property>
</bean>
</beans>

4.编写请求处理器

@Controller
public class TestController {

/**
*
* @Title: hello
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param: @return
* @return: String –当前方法处理完毕之后,要返回的视图名称
* @throws
*/
@RequestMapping(value=”/hello”)
public String hello () {
System.out.println(“我遭到了hello的甜蜜一击”);
return “success”;
}
}

5.编写视图

index.jsp

success.jsp

<body>
主页。。。。。
<a href=”hello”>hello world!</a>
</body>

版权声明:本文为ludengfu原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/ludengfu/p/9604703.html