本文主要是介绍配置一个简单的SpringMVC项目,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.添加jar包,如下:
2.配置web.xml (DispatcherServlet)
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param><param-name>contextConfigLocation </param-name><param-value>/WEB-INF/classes/spring-mvc.xml </param-value>
</context-param>
3.配置spring-mvc.xml (新建
Spring Bean Definition 选择beans context mvc)
<!-- 配置自定意掃描包 -->
<context:component-scan base-package="com.springMvc1"></context:component-scan>
<!-- 配置视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="WEB-INF/views/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
这篇关于配置一个简单的SpringMVC项目的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!