首页 新闻 会员 周边

ssm框架搭好,tomcat跑起来了,地址栏访问路径报错!

0
悬赏园豆:5 [待解决问题]

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>Archetype Created Web Application</display-name>

<!-- Spring配置 -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:config/applicationContext.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Spring MVC -->

<!-- <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:config/spring-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> -->

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<!--DispatcherServlet是前置控制器,配置在web.xml文件中的。拦截匹配的请求,Servlet拦截匹配规则要自已定义,把拦截下来的请求,依据某某规则分发到目标Controller(我们写的Action)来处理。 -->
<servlet>
    <servlet-name>DispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>         
     <!--指明了配置文件的文件名,不使用默认配置文件名,而使用dispatcher-servlet.xml配置文件。 -->
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:config/spring-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup><!--是启动顺序,让这个Servlet随Servletp容器一起启动。 -->
</servlet>
<servlet-mapping>
    <servlet-name>DispatcherServlet</servlet-name>
    <url-pattern>*.do</url-pattern> <!--会拦截URL中带“*.do”的请求。 -->
</servlet-mapping>

<!-- 设置字符集 -->
<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>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>characterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">

<!-- 扫描controller(controller层注入) -->
<context:component-scan base-package="cn.erp.web" />

<!-- 启动注解支持 -->
<mvc:annotation-driven />

<!-- 配置视图解析器 -->
<bean id="viewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView" />
    <!--指定视图的前缀 -->
    <property name="prefix" value="/jsp/" />
    <!--指定视图的后缀 -->
    <property name="suffix" value=".jsp" />
</bean>

</beans>

问题补充:

这是我的controller层

黑小子-余的主页 黑小子-余 | 初学一级 | 园豆:103
提问于:2019-07-07 20:42
< >
分享
所有回答(3)
0

请求路径有没有带.do

随风行云 | 园豆:936 (小虾三级) | 2019-07-07 21:28

大佬,我连我最原始的index.jsp页面都访问不了。

支持(0) 反对(0) 黑小子-余 | 园豆:103 (初学一级) | 2019-07-07 21:44
0

你这个WebApp是不是该放到resources目录下

~冰 | 园豆:509 (小虾三级) | 2019-07-08 14:20

maven项目结构生成就是这样的,问题找到了!

eclipse中的Tomcat的Servers中的Deploy Path:路径不对!!!

支持(0) 反对(0) 黑小子-余 | 园豆:103 (初学一级) | 2019-07-08 15:27
0

eclipse中的Tomcat的Servers中的Deploy Path:路径不对!!!真想打字及嘴巴子

黑小子-余 | 园豆:103 (初学一级) | 2019-07-08 15:29
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册