亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我的 Spring 應用程序不工作。404錯誤來了,而不是jsp文件

我的 Spring 應用程序不工作。404錯誤來了,而不是jsp文件

catspeake 2021-10-06 11:04:27
下面一個是我的 PageController.java 類package com.fayis.shopping.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.servlet.ModelAndView;@Controllerpublic class PageController {@RequestMapping(value = {"/","/home","/index"})public ModelAndView index(){    ModelAndView mv=new ModelAndView("page");    mv.addObject("greeting", "Hi");    return mv;}}下面是我的 Page.jsp 頁面<%@ page language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Insert title here</title></head><body>    test</body></html>下面一個是我的調度程序servlet dispatcher-servlet.xml<beans xmlns = "http://www.springframework.org/schema/beans"xmlns:context = "http://www.springframework.org/schema/context"xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation = "http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc htt p://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"><mvc:default-servlet-handler/><context:component-scan base-package="com.fayis.shopping.controller" /><beanclass="org.springframework.web.servlet.view.InternalResourceViewResolver">    <property name="prefix" value="/WEB-INF/view/" />    <property name="suffix" value=".jsp" /> </bean> </beans>
查看完整描述

2 回答

?
倚天杖

TA貢獻1828條經驗 獲得超3個贊

您尚未指定您的 servlet 容器,但例如在 tomcat 中要訪問您的應用程序,您必須在 URL 中包含您的 war 文件名,如下所示: localhost:8080/your_app-1.0-SNAPSHOT

其次,web.xml你有<url-pattern>/</url-pattern>which 只映射/而不會映射/indexor /home。要匹配此 URL,您的模式應如下所示<url-pattern>/*</url-pattern>


查看完整回答
反對 回復 2021-10-06
?
慕桂英4014372

TA貢獻1871條經驗 獲得超13個贊

它現在起作用了。簡直就像一個奇跡。當我更新 dispatcher-servlet spring bean 定義時,它起作用了。后來我把它改回來,仍然可以工作。


查看完整回答
反對 回復 2021-10-06
  • 2 回答
  • 0 關注
  • 247 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號