黔程似锦 2022-07-29 10:49 采纳率: 50%
浏览 31
已结题

ssm框架跳转页面路径缺失

ssm框架项目的时候tomcat启动都正常,但是点击图片跳转页面路径中间就会缺失/tickert,导致网页找不到,点击导演名页面路径完整,正常跳转,这是怎么回事,是我路径配置哪里出现了问题呢

img

img

img


controller层代码

package com.duing.controller;
 
import com.duing.service.FilmService;
import com.duing.vo.FilmDetailVo;
import com.duing.vo.FilmVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 
import java.util.List;
 
@Controller
public class FilmController {
    @Autowired
    private FilmService filmService;
    @RequestMapping("/filmList")
    @ResponseBody
    public List selectAll(){
        List filmVos = filmService.selectAll();
        return filmVos;
    }
    @RequestMapping("/home")
    public String home(Model model){
        System.out.println("接受首页请求");
        List filmVoList = filmService.selectAll();
        model.addAttribute("filmVoList",filmVoList);
        return "home";
    }
//    接受请求参数
    @RequestMapping("/filmInfo")
    public String filmInfo(@RequestParam String filmId, Model model){
        FilmDetailVo detailVo=filmService.findFilmById(filmId);
        model.addAttribute("detailVo",detailVo);
        return "detail";
    }
 
}


dao层

package com.duing.dao;
 
import com.duing.entity.Film;
 
import java.util.List;
 
public interface FilmDao {
    List getList();
    Film getFilmById(String filmId);
}


跟数据库映射的实体类

package com.duing.entity;
 
import java.io.Serializable;
import java.util.Date;
//  实体类 跟数据库的表映射
public class Film implements Serializable {
 
    private static final long serialVersionUID = -4427069375523038931L;
    private long id;
    private String film_id;
    private String name;
    private String director;
    private String player;
    private String type;
    private String country;
    private int length;
    private String synopsis;
    private Date play_time;
    private String img_path;
 
    public long getId() {
        return id;
    }
 
    public void setId(long id) {
        this.id = id;
    }
 
    public String getFilm_id() {
        return film_id;
    }
 
    public void setFilm_id(String film_id) {
        this.film_id = film_id;
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public String getDirector() {
        return director;
    }
 
    public void setDirector(String director) {
        this.director = director;
    }
 
    public String getPlayer() {
        return player;
    }
 
    public void setPlayer(String player) {
        this.player = player;
    }
 
    public String getType() {
        return type;
    }
 
    public void setType(String type) {
        this.type = type;
    }
 
    public String getCountry() {
        return country;
    }
 
    public void setCountry(String country) {
        this.country = country;
    }
 
    public int getLength() {
        return length;
    }
 
    public void setLength(int length) {
        this.length = length;
    }
 
    public String getSynopsis() {
        return synopsis;
    }
 
    public void setSynopsis(String synopsis) {
        this.synopsis = synopsis;
    }
 
    public Date getPlay_time() {
        return play_time;
    }
 
    public void setPlay_time(Date play_time) {
        this.play_time = play_time;
    }
 
    public String getImg_path() {
        return img_path;
    }
 
    public void setImg_path(String img_path) {
        this.img_path = img_path;
    }
}

service层

package com.duing.entity;
 
import java.io.Serializable;
import java.util.Date;
//  实体类 跟数据库的表映射
public class Film implements Serializable {
 
    private static final long serialVersionUID = -4427069375523038931L;
    private long id;
    private String film_id;
    private String name;
    private String director;
    private String player;
    private String type;
    private String country;
    private int length;
    private String synopsis;
    private Date play_time;
    private String img_path;
 
    public long getId() {
        return id;
    }
 
    public void setId(long id) {
        this.id = id;
    }
 
    public String getFilm_id() {
        return film_id;
    }
 
    public void setFilm_id(String film_id) {
        this.film_id = film_id;
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public String getDirector() {
        return director;
    }
 
    public void setDirector(String director) {
        this.director = director;
    }
 
    public String getPlayer() {
        return player;
    }
 
    public void setPlayer(String player) {
        this.player = player;
    }
 
    public String getType() {
        return type;
    }
 
    public void setType(String type) {
        this.type = type;
    }
 
    public String getCountry() {
        return country;
    }
 
    public void setCountry(String country) {
        this.country = country;
    }
 
    public int getLength() {
        return length;
    }
 
    public void setLength(int length) {
        this.length = length;
    }
 
    public String getSynopsis() {
        return synopsis;
    }
 
    public void setSynopsis(String synopsis) {
        this.synopsis = synopsis;
    }
 
    public Date getPlay_time() {
        return play_time;
    }
 
    public void setPlay_time(Date play_time) {
        this.play_time = play_time;
    }
 
    public String getImg_path() {
        return img_path;
    }
 
    public void setImg_path(String img_path) {
        this.img_path = img_path;
    }
}


service接口

package com.duing.service;
 
import com.duing.vo.FilmDetailVo;
import com.duing.vo.FilmVo;
 
import java.util.List;
 
public interface FilmService {
    List selectAll();
    FilmDetailVo findFilmById(String filmId);
}


vo数据

package com.duing.vo;
 
import java.util.Date;
 
public class FilmDetailVo {
    private String filmId;
    private String name;
    private String director;
    private String player;
    private String type;
    private String country;
    private int length;
    private String synopsis;
    private Date playTime;
    private String imgPath;
 
    public String getFilmId() {
        return filmId;
    }
 
    public void setFilmId(String filmId) {
        this.filmId = filmId;
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public String getDirector() {
        return director;
    }
 
    public void setDirector(String director) {
        this.director = director;
    }
 
    public String getPlayer() {
        return player;
    }
 
    public void setPlayer(String player) {
        this.player = player;
    }
 
    public String getType() {
        return type;
    }
 
    public void setType(String type) {
        this.type = type;
    }
 
    public String getCountry() {
        return country;
    }
 
    public void setCountry(String country) {
        this.country = country;
    }
 
    public int getLength() {
        return length;
    }
 
    public void setLength(int length) {
        this.length = length;
    }
 
    public String getSynopsis() {
        return synopsis;
    }
 
    public void setSynopsis(String synopsis) {
        this.synopsis = synopsis;
    }
 
    public Date getPlayTime() {
        return playTime;
    }
 
    public void setPlayTime(Date playTime) {
        this.playTime = playTime;
    }
 
    public String getImgPath() {
        return imgPath;
    }
 
    public void setImgPath(String imgPath) {
        this.imgPath = imgPath;
    }
}

package com.duing.vo;
//  视图层对象 用来展示给用户使用
public class FilmVo {
    private String filmId;
    private String name;
    private String director;
    private String imgPath;
 
    public String getFilmId() {
        return filmId;
    }
 
    public void setFilmId(String filmId) {
        this.filmId = filmId;
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public String getDirector() {
        return director;
    }
 
    public void setDirector(String director) {
        this.director = director;
    }
 
    public String getImgPath() {
        return imgPath;
    }
 
    public void setImgPath(String imgpath) {
        this.imgPath = imgpath;
    }
}

mapper配置文件

package com.duing.vo;
//  视图层对象 用来展示给用户使用
public class FilmVo {
    private String filmId;
    private String name;
    private String director;
    private String imgPath;
 
    public String getFilmId() {
        return filmId;
    }
 
    public void setFilmId(String filmId) {
        this.filmId = filmId;
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public String getDirector() {
        return director;
    }
 
    public void setDirector(String director) {
        this.director = director;
    }
 
    public String getImgPath() {
        return imgPath;
    }
 
    public void setImgPath(String imgpath) {
        this.imgPath = imgpath;
    }
}


mybatis配置

configuration
       PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
 
    <mappers>
        <package name="com.duing.dao"/>
    mappers>
 
configuration>

spring配置

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
        http://www.springframework.org/schema/aop
        https://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        https://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/context
        https://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc
        https://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd">
    <context:component-scan base-package="com.duing.service"/>
 
    <context:property-placeholder location="classpath:druid.properties"/>
 
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    bean>
    <bean id="factory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="configLocation" value="classpath:/mybatis.xml"/>
        <property name="mapperLocations" value="classpath:mappers/*.xml"/>
    bean>
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="sqlSessionFactoryBeanName" value="factory"/>
        <property name="basePackage" value="com.duing.dao"/>
    bean>
beans>


springmvc配置

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
        http://www.springframework.org/schema/context
        https://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc
        https://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd">
    <context:component-scan base-package="com.duing.controller"/>
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
    bean>
    <mvc:resources mapping="/img/**" location="/img/"/>
    <mvc:resources mapping="/css/**" location="/css/"/>
    <mvc:annotation-driven/>
beans>

jsp文件

<%--
  Created by IntelliJ IDEA.
  User: 22018
  Date: 2022/7/28
  Time: 15:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <title>Titletitle>
head>
<body>
    
<img src="${pageContext.request.contextPath}${detailVo.imgPath}">

${detailVo.name}p>

${detailVo.country}p>

${detailVo.length}分钟p>

${detailVo.director}p>

${detailVo.player}p>

${detailVo.synopsis}p> div> body> html>

web配置

<web-app 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_3_0.xsd"
         version="3.0">
 
    <context-param>
        <param-name>contextConfigLocationparam-name>
        <param-value>classpath:/spring.xmlparam-value>
    context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
    listener>
    <servlet>
        <servlet-name>DispatcherServletservlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
        <init-param>
            <param-name>contextConfigLocationparam-name>
            <param-value>classpath:/springmvc.xmlparam-value>
        init-param>
        <load-on-startup>1load-on-startup>
    servlet>
    
    <servlet-mapping>
        <servlet-name>DispatcherServletservlet-name>
        <url-pattern>/url-pattern>
    servlet-mapping>
 
    <filter>
        <filter-name>characterEncodingFilterfilter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
        <init-param>
            <param-name>encodingparam-name>
            <param-value>utf-8param-value>
        init-param>
        <init-param>
            <param-name>forceRequestEncodingparam-name>
            <param-value>trueparam-value>
        init-param>
        <init-param>
            <param-name>forceResponseEncodingparam-name>
            <param-value>trueparam-value>
        init-param>
 
    filter>
    <filter-mapping>
        <filter-name>characterEncodingFilterfilter-name>
        <url-pattern>/*url-pattern>
    filter-mapping>
web-app>


index文件

<html>
<body>
<h2>Hello World!h2>
<jsp:forward page="/home"/>
body>
html>


  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 8月6日
    • 创建了问题 7月29日

    悬赏问题

    • ¥15 github录制项目
    • ¥15 H.264选择性加密例程
    • ¥50 windows的SFTP服务器如何能批量同步用户信息?
    • ¥15 centos7.9升级python3.0的问题
    • ¥15 如何解决调试dev-出++5.11不成功问题
    • ¥15 安装CentOS6时卡住
    • ¥20 关于#监控系统#的问题,如何解决?(相关搜索:系统软件)
    • ¥20 c语言写的8051单片机存储器mt29的模块程序
    • ¥60 求直线方程 使平面上n个点在直线同侧并且距离总和最小
    • ¥50 java算法,给定试题的难度数量(简单,普通,困难),和试题类型数量(单选,多选,判断),以及题库中各种类型的题有多少道,求能否随机抽题。