Java HTTP - 500 org.springframework.web.util.NestedServletException:处理程序处理失败;

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4073818/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 11:18:41  来源:igfitidea点击:

HTTP - 500 org.springframework.web.util.NestedServletException: Handler processing failed;

javaspring-mvc

提问by Sal Prima

I'm using :

我正在使用 :

  1. Apache Tomcat 6.0.20
  2. Spring 3.x
  1. Apache Tomcat 6.0.20
  2. 弹簧 3.x

I want to create simple "Hello World !!!" on my index page. Unfortunately, I get the following error:

我想创建简单的“Hello World !!!” 在我的索引页上。不幸的是,我收到以下错误:

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:820)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

this is my controller called IndexController.java

这是我的控制器,名为IndexController.java

package com.dprima.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class IndexController {
    @RequestMapping("/index")
    public ModelAndView index(){
        String message = "Hello World !!!";
        return new ModelAndView("index","hello",message);
    }
}

my web.xml

我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>passion</display-name>
    <servlet>
        <servlet-name>dispatcher</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

      <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.php</url-pattern>
      </servlet-mapping>

      <welcome-file-list>
        <welcome-file>redirect.jsp</welcome-file>
      </welcome-file-list>
</web-app>

my dispatcher-servlet.xml

我的调度程序-servlet.xml

 ...
        <context:component-scan base-package="com.dprima.controller" />

        <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
            <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
            <property name="prefix" value="/WEB-INF/jsp/" />
            <property name="suffix" value=".jsp" />
        </bean> 
    ...

my redirect.jsp

我的redirect.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<% response.sendRedirect("index.php"); %>

my index.jsp

我的index.jsp

<html>
<head>
    <title>Spring 3</title>
</head>
<body>
    ${hello}
</body>
</html>

I have added all JARs including jstl.jar& standard.jarbecause I assume this will required for the java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Configerror. However, it still displays HTTP 500 for the http://localhost:8080/passion/index.phpand HTTP 404 for http://localhost:8080/passion/.

我已经添加了包括jstl.jarstandard.jar在内的所有 JAR ,因为我认为这对于java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config错误是必需的。然而,它仍显示HTTP 500的HTTP://本地主机:8080 /激情/ index.php的和HTTP 404为HTTP://本地主机:8080 /激情/

采纳答案by duffymo

JARs should be in WEB-INF/lib, not subdirectories.

JAR 应该在 WEB-INF/lib 中,而不是子目录中。

If you're deploying on Tomcat, you might try putting those JSTL JARs in the Tomcat /lib so the server class loader can find them.

如果您在 Tomcat 上部署,您可以尝试将这些 JSTL JAR 放在 Tomcat /lib 中,以便服务器类加载器可以找到它们。

回答by danny.lesnik

, Why do you redirect this page using?

,你为什么重定向这个页面使用?

<% response.sendRedirect("index.php"); %>

you can map index php as a welcome file. I did it the following way:

您可以将 index php 映射为欢迎文件。我是通过以下方式做到的:

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/index.php</url-pattern>
  </servlet-mapping>

and then:

进而:

 <welcome-file-list>
        <welcome-file>index.php</welcome-file>
      </welcome-file-list>

it will show your index.dlp as index file. Danny.

它会将您的 index.dlp 显示为索引文件。丹尼。

回答by Alvin

I think that you must be use tomcat and your pom.xml is like:

我认为你必须使用 tomcat 并且你的 pom.xml 是这样的:

<dependency>
    <groupId>javax.servlet.jsp.jstl</groupId>
    <artifactId>jstl-api</artifactId>
    <version>1.2</version>
    <scope>provided</scope>
</dependency>

delete the scope node, or change "provided" to "compile" then maven copy jstl-api-1.2.jar to the WEB-INF/lib.

删除范围节点,或将“provided”改为“compile”,然后maven将jstl-api-1.2.jar复制到WEB-INF/lib。

then OK.

然后确定。