标签:
1.首先,导入SpringMVC需要的jar包。
2、添加Web.xml配置文件中关于SpringMVC的配置
<!--configure the setting of springmvcDispatcherServlet and configure the mapping-->
<
servlet
>
<
servlet-name
>springmvc</
servlet-name
>
<
servlet-class
>org.springframework.web.servlet.DispatcherServlet</
servlet-class
>
<
init-param
>
<
param-name
>contextConfigLocation</
param-name
>
<
param-value
>classpath:springmvc-servlet.xml</
param-value
>
</
init-param
>
<!-- <load-on-startup>1</load-on-startup> -->
</
servlet
>
<
servlet-mapping
>
<
servlet-name
>springmvc</
servlet-name
>
<
url-pattern
>/</
url-pattern
>
</
servlet-mapping
>
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
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
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
<!-- scan the package and the sub package -->
<
context:component-scan
base-package
=
"test.SpringMVC"
/>
<!-- don‘t handle the static resource -->
<
mvc:default-servlet-handler
/>
<!-- if you use annotation you must configure following setting -->
<
mvc:annotation-driven
/>
<!-- configure the InternalResourceViewResolver -->
<
bean
class
=
"org.springframework.web.servlet.view.InternalResourceViewResolver"
id
=
"internalResourceViewResolver"
>
<!-- 前缀 -->
<
property
name
=
"prefix"
value
=
"/WEB-INF/jsp/"
/>
<!-- 后缀 -->
<
property
name
=
"suffix"
value
=
".jsp"
/>
</
bean
>
</
beans
>
@Controller
@RequestMapping
(
"/mvc"
)
public
class
mvcController {
@RequestMapping
(
"/hello"
)
public
String hello(){
return
"hello"
;
}
}
标签:
原文地址:http://www.cnblogs.com/taz372436/p/5481661.html