页面跳转为404

页面跳转为404

我复制粘贴源代码,输入http://localhost:8080/sm/department/list.jsp,启动服务器后,跳转成404

package com.imooc.sm.dao;

import com.imooc.sm.entity.Department;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository("departmentDao")
public interface DepartmentDao {
    void insert(Department department);
    void delete(Integer id);
    void update(Department department);
    Department selectById(Integer id);
    List<Department> selectAll();
}
package com.imooc.sm.service;

import com.imooc.sm.entity.Department;

import java.util.List;

public interface DepartmentService {
    void add(Department department);
    void remove(Integer id);
    void edit(Department department);
    Department get(Integer id);
    List<Department> getAll();
}

package com.imooc.sm.service.impl;

import com.imooc.sm.dao.DepartmentDao;
import com.imooc.sm.entity.Department;
import com.imooc.sm.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;
@Service("departmentService")
public class DepartmentServiceImpl implements DepartmentService {
   @Qualifier("departmentDao")
   @Autowired
   private DepartmentDao departmentDao;

   public void add(Department department) {
       departmentDao.insert(department);
   }

   public void remove(Integer id) {
       departmentDao.delete(id);
   }

   public void edit(Department department) {
       departmentDao.update(department);
   }

   public Department get(Integer id) {
       return departmentDao.selectById(id);
   }

   public List<Department> getAll() {
       return departmentDao.selectAll();
   }
}

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;

@Controller("departmentControllter")
public class DepartmentControllter {
   @Autowired
   private DepartmentService departmentService;
   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);
   }
}


正在回答

登陆购买课程后可参与讨论,去登陆

2回答

同学你好,404错误是路径不正确,这里应该访问http://localhost:8080/sm/department/list.do,通过转发跳转到对应的页面中。另外如果如下的application context中没有写项目名,那么访问路径中不需要加项目名,如:

http://img1.sycdn.imooc.com//climg/5e7ec9d209d0e23e03250087.jpg

如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~

  • TT拖鞋 提问者 #1
    路径是一个问题,类名我也写错了,访问不到,所有404,但是我改好后,页面跳转成功,但是是空白页面。
    2020-03-28 21:52:23
  • TT拖鞋 提问者 #2
    问题解决了,页面成功显示....是配置文件路径的创建问题,真~一包烟一杯茶,一个bug调一天。
    2020-03-28 22:13:12
提问者 TT拖鞋 2020-03-28 00:38:24
这是departmentDao.xml的代码
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.4//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.imooc.sm.dao.DepartmentDao">
    <resultMap id="resultMap" type="Department">
        <id property="id" column="id" javaType="Integer"/>
        <result property="name" column="name" javaType="String"/>
        <result property="address" column="address" javaType="String"/>
    </resultMap>

    <insert id="insert" parameterType="Department" useGeneratedKeys="true">
        insert into department(name,address) values(#{name},#{address})
    </insert>
    <delete id="delete" parameterType="Integer">
        delete from department where id=#{id}
    </delete>
    <update id="update" parameterType="Department">
        update department set name=#{name},address=#{address} where id=#{id}
    </update>
    <select id="selectById" parameterType="Integer" resultMap="resultMap">
        select * from department where id=#{id}
    </select>
    <select id="selectAll" resultMap="resultMap">
        select * from department
    </select>
</mapper>


问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师