<span style="font-family: Arial, Helvetica, sans-serif;"> 本人使用版本为:myeclipse10.0</span>
最近一直在看springmvc,由于之前使用myeclipse并没有注意到有myeclipse能便捷搭设框架。所有基本都是自己一个文件一个文件的建,自己下jar包。然后导入进去再写web.xml和springmvc-servlet.xml。 后来觉得麻烦 就专门查了下myeclipse搭建springmvc框架,终于,在度娘的帮助下,让我找到了。
1.在myeclipse中创建一个web project。
2.右键点击这个项目选择Myeclipse
3.选择要导入的spring包,然后next,选择spring-servlet要放的位置然后finish
4.根据自己的习惯修改web.xml和spring-servlet.xml文件
代码如下:
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">
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>
spring
</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>
spring
</servlet-name>
<url-pattern>
*.do
</url-pattern>
</servlet-mapping>
</web-app>
spring-servlet.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
<span style="white-space:pre"> </span> http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
<span style="white-space:pre"> </span> http://www.springframework.org/schema/tx
<span style="white-space:pre"> </span> http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
<span style="white-space:pre"> </span> http://www.springframework.org/schema/context
<span style="white-space:pre"> </span> http://www.springframework.org/schema/context/spring-context-3.0.xsd
<span style="white-space:pre"> </span> http://www.springframework.org/schema/mvc
<span style="white-space:pre"> </span> http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!-- 扫描controller -->
<span style="white-space:pre"> </span><context:component-scan base-package="com.yu.conl" />
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span><bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<span style="white-space:pre"> </span><property name="prefix"><value>/WEB-INF/jsp/</value></property>
<span style="white-space:pre"> </span><property name="suffix"><value>.jsp</value></property>
<span style="white-space:pre"> </span></bean>
</beans>
一切搞定就可以开始写你的程序了