启动⼀个简单的maven项⽬
2.写好Group Id 和Artifact Id ,Packaging选择 war
3.建好⼯程后会报错,右键Deployment Descriptor:demo2  选择最长的Generate Deployment Descriptor stub ,此时会⾃动创建l,报错消失。
4.现在可以创建l如下:
<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>(配置l的路径很重要,要是配置错误的话,会报错不到⽂件的错误)
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:/l</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.然后写好l
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="/schema/beans"
xmlns:xsi="/2001/XMLSchema-instance"
xmlns:context="/schema/context"
xmlns:jdbc="/schema/jdbc"
xmlns:jee="/schema/jee"
xmlns:tx="/schema/tx"
xmlns:aop="/schema/aop"
xmlns:mvc="/schema/mvc"
xmlns:util="/schema/util"
xmlns:jpa="/schema/data/jpa"
xsi:schemaLocation="
/schema/beans /schema/beans/spring-beans-3.2.xsd
/schema/context /schema/context/spring-context-3.2.xsd
/schema/jdbc /schema/jdbc/spring-jdbc-3.2.xsd
/schema/jee /schema/jee/spring-jee-3.2.xsd
/schema/tx /schema/tx/spring-tx-3.2.xsd
/schema/data/jpa /schema/data/jpa/spring-jpa-1.3.xsd
/schema/aop /schema/aop/spring-aop-3.2.xsd
/schema/mvc /schema/mvc/spring-mvc-3.2.xsd
/schema/util /schema/util/spring-util-3.2.xsd">
<!-- Spring MVC -->
<!-- 配置组件扫描 -->
<context:component-scan
base-package="ller"/>
<!-- 配置ViewResolver配置视图解析器 r -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix"
value="/web/"/>
<property name="suffix"
value=".jsp"/>
</bean>
<!-- 注解驱动 -->
<mvc:annotation-driven />
</beans>
l--这个l中有⼀些是⽤不到的,基本的都在这⾥可以参考。
注:
  如果没有servlet的jar包会导致jsp页⾯报错。
  如果你的jdk版本是1.8,spring的版本要是4.0以上的,否则不兼容,导致扫描不到包。
<project xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance" xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd" <modelVersion>4.0.0</modelVersion>
<groupId>cn.frode</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<!-- spring-webmvc 如果是jdk8的话需要⽤spring4.0以上的版本-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2.6.RELEASE</version>
</dependency>
<!-- spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.2.6.RELEASE</version>
</dependency>
<!-- servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- junit-单元测试-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<!-- mybatis,mybatis-spring -->
<dependency>
<groupId&batis</groupId>
<artifactId>mybatis</artifactId>
jpa mybatis
<version>3.2.5</version>
</dependency>
<dependency>
<groupId&batis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.1</version>
</dependency>
<!-- mysql,commons-dbcp -->
<!--    <dependency>
<groupId>mysql-connector-java</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.37</version>
</dependency> -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<!-- jackson * 3 -->
<dependency>
<groupId>com.</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.3</version>
</dependency>
<dependency>
<groupId>com.</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.3</version>
</dependency>
<dependency>
<groupId>com.</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.3</version>
</dependency>
<!-- jstl -->
<!-- <dependency>
<groupId>Jstl</groupId>
<artifactId>Jstl</artifactId>
<version>1.2</version>
</dependency>  -->
<!-- 消息摘要技术jar包 -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<!-- ⽂件上传依赖jar包 -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.2</version>
</dependency>
<!-- ⽂件上传 -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
</project>
7.jsp⽂件放置的路径
解决jsp字符集设置的问题:
填写字符集之后点击Update,以后新建的jsp页⾯都是这个设置的字符集了。
package ller;
@Controller
@RequestMapping("/user")//
public class FrodeController {
@RequestMapping("/hello")
public String hello(){
return "hello";
}
}
8.访问成功
默认情况下访问l中的welcome-file的配置页⾯
通过DispatcherServlet分发给controller在返回给ModelAndView进⾏解析的页⾯
附上我的项⽬的路径
这样就可以将⼀个简单的项⽬⾛通了!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。