标签:配置 other control star desc simple lis source ann
1.eclipse-file-new-other:搜索maven,建立一个maven项目,勾选上 Create a simple project点击finish
2.写好Group Id 和Artifact Id ,Packaging选择 war
3.建好工程后会报错,右键Deployment Descriptor:demo2 选择最长的Generate Deployment Descriptor stub ,此时会自动创建web.xml,报错消失。
4.现在可以创建web.xml如下:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>SpringMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>(配置spring-mvc.xml的路径很重要,要是配置错误的话,会报错找不到文件的错误)
<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>SpringMVC</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
5.然后写好spring-mvc.xml
<!-- 扫描对应的包名,不要写错-->
<context:component-scan
base-package="cn.frode.controller" />
<!-- 配置ViewResolver配置视图解析器 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix"
value="/web/" />
<property name="suffix"
value=".jsp" />
</bean>
<!-- 注解驱动 (这个很重要)-->
<mvc:annotation-driven />
6.然后写好对应的controller,再对应的路径下写好jsp或者html文件就成功了!
标签:配置 other control star desc simple lis source ann
原文地址:https://www.cnblogs.com/fengxiaoyuan/p/9866025.html