jsp页面报错 找不到页面
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jsp页面报错 找不到页面相关的知识,希望对你有一定的参考价值。
我最近做了个网站,在本机的MyEclipse上运行一点问题都没有,挂在服务器上也没有问题,但是一配置域名直接连接的jsp页面都访问不到404报错,而通过action访问的都没问题。服务器是自己配置的用的是tomcat6.0 jdk1.6 网站用ssh框架做的 ,请问这是怎么回事,希望高手指点下
也许是我tomcat配置出错了,在service.xml默认网站我改成localhost就没问题 如果换成网址就出现了上面的问题 还真是头痛
检查下tomcat启动过程是不是启动成功结束了,过程有没有报错,检查下Tomcat的配置文件,是不是 指到了Web目录 参考技术A 同样路径action能找到jsp找不到路径错误应该是很明显的,是不是用了什么伪静态的或者filter拦截设置问题本回答被提问者采纳 参考技术B 你仔细看看 IE地址栏
看看却什么 就在页面上加什么 参考技术C 文件引用路径的问题, path
Spring Boot JSP 404:找不到页面
【中文标题】Spring Boot JSP 404:找不到页面【英文标题】:Spring boot JSP 404: Page not found 【发布时间】:2020-03-08 06:41:07 【问题描述】:我正在尝试运行一个简单的 Spring Boot 应用程序。但是,当我运行它时,我收到以下错误:
“白标错误页面 此应用程序没有明确的 /error 映射,因此您将其视为后备。”
2019 年 11 月 12 日星期二 09:31:36 AST 出现意外错误(类型=未找到,状态=404)。 /WEB-INF/view/index.jsp
这是我的 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>jspDemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>jspDemo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<!-- JSTL -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- To compile JSP files -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
IndexController.java
package com.pack.springMVC;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class IndexController
@RequestMapping("/")
public String home(Map<String, Object> model)
model.put("message", "HowToDoInJava Reader !!");
return "index";
@RequestMapping("/next")
public String next(Map<String, Object> model)
model.put("message", "You are in new page !!");
return "next";
MvcConfiguration.java
package com.pack.springMVC;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
@Configuration
@EnableWebMvc
@ComponentScan
public class MvcConfiguration implements WebMvcConfigurer
@Override
public void configureViewResolvers(ViewResolverRegistry registry)
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/view/");
resolver.setSuffix(".jsp");
resolver.setViewClass(JstlView.class);
registry.viewResolver(resolver);
JspDemoApplication.java
package com.pack.springMVC;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class JspDemoApplication extends SpringBootServletInitializer
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application)
return application.sources(JspDemoApplication.class);
public static void main(String[] args)
SpringApplication.run(JspDemoApplication.class, args);
index.jsp
<!DOCTYPE html>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<html lang="en">
<body>
<div>
<div>
<h1>Spring Boot JSP Example</h1>
<h2>Hello $message</h2>
Click on this <strong><a href="next">link</a></strong> to visit another page.
</div>
</div>
</body>
</html>
下一个.jsp
<!DOCTYPE html>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<html lang="en">
<body>
<div>
<div>
<h1>Another page</h1>
<h2>Hello $message</h2>
Click on this <strong><a href="/">link</a></strong> to visit previous page.
</div>
</div>
</body>
</html>
application.properties
spring.mvc.view.prefix=/WEB-INF/view/ spring.mvc.view.suffix=.jsp
【问题讨论】:
index.jsp的路径是什么 src/main/resource/webapp/WEB-INF/view/index.jsp 【参考方案1】:试试这个
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
@Configuration
@EnableWebMvc
@ComponentScan
public class MvcConfiguration extends WebMvcConfigurerAdapter
@Override
public void configureViewResolvers(ViewResolverRegistry registry)
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/view/");
resolver.setSuffix(".jsp");
resolver.setViewClass(JstlView.class);
registry.viewResolver(resolver);
【讨论】:
以上是关于jsp页面报错 找不到页面的主要内容,如果未能解决你的问题,请参考以下文章
Spring MVC 注释。 + Jetty 9 + 查看解析器 - 找不到 jsp 页面
yii2 表单提交一直报错 或者页面脚本写ajax,用firbug调试总是找不到地址页面404