404错误

来源:4-3 部门管理实现-界面

IT菜鸟123

2019-01-18 19:28:37

Controller

package com.imooc.sm.controller;

import com.imooc.sm.entity.Department;
import com.imooc.sm.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author wangc
 */
@Controller("departmentController")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    /**
     * /department/list.do     /department_list.jsp
     */
    public void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Department> list = departmentService.getAll();
        request.setAttribute("LIST", list);
        request.getRequestDispatcher("../department_list.jsp").forward(request, response);
    }
}

sm_web项目web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

  <filter>
    <filter-name>Encoding</filter-name>
    <filter-class>com.imooc.sm.global.EncodingFilter</filter-class>
    <init-param>
      <param-name>ENCODING</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>

  <filter-mapping>
    <filter-name>Encoding</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <!--<filter>-->
    <!--<filter-name>Login</filter-name>-->
    <!--<filter-class>com.imooc.sm.global.LoginFilter</filter-class>-->
  <!--</filter>-->

  <!--<filter-mapping>-->
    <!--<filter-name>Login</filter-name>-->
    <!--<url-pattern>*.jsp</url-pattern>-->
  <!--</filter-mapping>-->
  <!--<filter-mapping>-->
    <!--<filter-name>Login</filter-name>-->
    <!--<url-pattern>*.do</url-pattern>-->
  <!--</filter-mapping>-->


  <servlet>
    <servlet-name>Global</servlet-name>
    <servlet-class>com.imooc.sm.global.DispatcherServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Global</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>

  
</web-app>

sm_service项目spring.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:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       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.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd">
    <!-- Spring整合Mybatis -->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/sm?useUnicode=true&amp;characterEncoding=utf-8"/>
        <property name="username" value="root"/>
        <property name="password" value="123456"/>
    </bean>
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="typeAliasesPackage" value="com.imooc.sm.entity"/>
    </bean>
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.imooc.sm.dao"/>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
    </bean>
    <!-- 声明式事务 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="get*" read-only="true"/>
            <tx:method name="find*" read-only="true"/>
            <tx:method name="search*" read-only="true"/>
            <tx:method name="*" propagation="REQUIRED"/>
        </tx:attributes>
    </tx:advice>
    <aop:config>
        <aop:pointcut id="txPointcut" expression="execution(* com.imooc.sm.service.*.*(..))"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>
    </aop:config>
    <!-- 全局扫描 -->
    <context:component-scan base-package="com.imooc.sm"/>
    <aop:aspectj-autoproxy/>
</beans>


写回答

1回答

好帮手慕阿莹

2019-01-20

1、请同学截图一下你的目录结构(截图的时候展开你的目录)。

2、请同学截图一下你的404页面,包括url中的地址。

3、404是找不到地址报错的,同学可以先自己检查一下路径是否正确呢?

4、department_list.jsp如果是在webContext目录下,转发的时候不用写../,直接写成

 request.getRequestDispatcher("/department_list.jsp").forward(request, response);即可

祝学习愉快。

0

0 学习 · 4317 问题

查看课程