简体   繁体   English

HTTP 500 - 内部服务器错误。 servlet spring-dispatcher 的 Servlet.init() 抛出异常

[英]HTTP 500 - INTERNAL SERVER ERROR. Servlet.init() for servlet spring-dispatcher threw exception

I'm a Spring MVC beginner and I'm following a tutorial about how to use it.我是 Spring MVC 初学者,我正在学习如何使用它的教程。 On my main page which is "http://localhost:8080/FitnessTracker/" I don't have any problems, but when I try to access to, for example, "http://localhost:8080/FitnessTracker/addGoal.html", it says what i wrote on the title.在我的主页“http://localhost:8080/FitnessTracker/”上我没有任何问题,但是当我尝试访问例如“http://localhost:8080/FitnessTracker/addGoal. html”,它说明了我在标题上写的内容。

My web.xml is the next one:我的 web.xml 是下一个:

<web-app version="2.5" 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_2_5.xsd">

    <servlet>
        <servlet-name>fitTrackerServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/config/servlet-config.xml</param-value>
        </init-param>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>fitTrackerServlet</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>
    
    <servlet-mapping>
        <servlet-name>fitTrackerServlet</servlet-name>
        <url-pattern>/pdfs/**</url-pattern>
    </servlet-mapping>
    
    <servlet-mapping>
        <servlet-name>fitTrackerServlet</servlet-name>
        <url-pattern>/images/**</url-pattern>
    </servlet-mapping>
    
    <servlet-mapping>
        <servlet-name>fitTrackerServlet</servlet-name>
        <url-pattern>*.json</url-pattern>
    </servlet-mapping>
    
    <display-name>Archetype Created Web Application</display-name>
</web-app>

My servlet-config.xml has this:我的 servlet-config.xml 有这个:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <mvc:annotation-driven/>
    
    <mvc:resources location="assets" mapping="/assets/**"/>
    <mvc:resources location="pdfs" mapping="/pdfs/**"/>
    
    <context:component-scan base-package="com.pluralsight"/>
    
    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <property name="order" value="1" />
        <property name="contentNegotiationManager">
            <bean class="org.springframework.web.accept.ContentNegotiationManager">
                <constructor-arg>
                    <bean class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy">
                        <constructor-arg>
                            <map>
                                <entry key="json" value="application/json" />
                                <entry key="xml" value="application/xml" />
                            </map>
                        </constructor-arg>
                    </bean>
                </constructor-arg>
            </bean>
        </property>
        
        <property name="defaultViews">
            <list>
                <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
                <bean class="org.springframework.web.servlet.view.xml.MarshallingView">
                    <constructor-arg>
                        <bean class="org.springframework.oxm.xstream.XStreamMarshaller">
                            <property name="autodetectAnnotations" value="true" />
                        </bean>
                    </constructor-arg>
                </bean>
            </list>
        </property>
    </bean>
    
    <mvc:interceptors>
        <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" p:paramName="language"/>
    </mvc:interceptors>
    
    <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" p:defaultLocale="en"/>
    
    <bean id="messageSource" 
    class="org.springframework.context.support.ResourceBundleMessageSource" 
    p:basename="messages"></bean>
    
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
     p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" p:order="2"/>
        
     <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="0"/>

</beans>

This is my addGoal.jsp file这是我的 addGoal.jsp 文件

    pageEncoding="ISO-8859-1"%>

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>


<!DOCTYPE html>
<html lang="en">
  
  <head>
    <meta charset="utf-8">
    <title>
    </title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Le styles -->
    <link href="assets/css/bootstrap.css" rel="stylesheet">
    <style>
      body { padding-top: 60px; /* 60px to make the container go all the way
      to the bottom of the topbar */ }
    </style>
    <link href="assets/css/bootstrap-responsive.css" rel="stylesheet">
    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js">
      </script>
    <![endif]-->
    <!-- Le fav and touch icons -->
    <link rel="shortcut icon" href="assets/ico/favicon.ico">
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png">
    <link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png">
    <style>
        .error {
            color: #ff0000;
        }
        
        .errorblock {
            color: #000;
            background-color: #ffEEEE;
            border: 3px solid #ff0000;
            padding: 8px;
            margin: 16px;
        }
    </style>
  </head>
  <body>
    <div class="navbar navbar-fixed-top navbar-inverse">
      <div class="navbar-inner">
        <div class="container">
          <a class="brand" href="#">
            Add Goal
          </a>
          <ul class="nav">
          </ul>
        </div>
      </div>
    </div>
    <div class="container">
      <div>
        <h1>
          Add Goal
        </h1>
        <p>
          Add your workout goal in minutes for the day.
          <br>
          &nbsp;
        </p>
      </div>
      
      <form:form commandName="goal">
        <form:errors path="*" cssClass="errorblock" element="div" />
            <label for="textinput1">
              Enter Minutes:
            </label>    
            <form:input path="minutes" cssErrorClass="error" />
            <form:errors path="minutes" cssClass="error" />
            <br/>
            <input type="submit" class="btn" value="Enter Goal Minutes"/>
      </form:form>
     
      <div class="control-group">
      </div>
    </div>

     <script src="jquery-1.8.3.js">
    </script>
    <script src="assets/js/bootstrap.js">
    </script>
  </body>
</html>

My GoalController.java我的目标控制器.java


import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.pluralsight.model.Goal;

@Controller
@SessionAttributes("goal")
public class GoalController {

    @RequestMapping(value = "addGoal", method = RequestMethod.GET)
    public String addGoal(Model model) {
        Goal goal = new Goal();
        goal.setMinutes(10);
        model.addAttribute("goal", goal);
        
        return "addGoal";
    }
    
    @RequestMapping(value = "addGoal", method = RequestMethod.POST)
    public String updateGoal(@Valid @ModelAttribute("goal") Goal goal, BindingResult result) {
        
        System.out.println("result has errors: " + result.hasErrors());
        
        System.out.println("Goal set: " + goal.getMinutes());
        
        if(result.hasErrors()) {
            return "addGoal";
        }
        
        return "redirect:index.jsp";
    }
    
}

And I'm having this exception我有这个例外

    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:492)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1201)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:654)
    org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2532)
    org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2521)
    java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.base/java.lang.Thread.run(Thread.java:830)

What can I do to make this work?我能做些什么来完成这项工作? Thank you so much.太感谢了。

Add this in web.xml在 web.xml 中添加这个

<!-- Set up URL mapping for Spring MVC Dispatcher Servlet -->
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

In web.xml why are you having more than one servlet mapping of single servlet My suggestion would be please remove all these servlet mapping and then just include which I have told you above在 web.xml 为什么你有多个单个 servlet 的 servlet 映射我的建议是请删除所有这些 servlet 映射,然后只包括我在上面告诉你的

Try to access localhost:8080/FitnessTracker/addGoal as per your controller code尝试根据您的 controller 代码访问 localhost:8080/FitnessTracker/addGoal

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring MVC HTTP状态500 –内部服务器错误,Servlet [dispatcher]的Servlet.init()抛出异常 - Spring MVC HTTP Status 500 – Internal Server Error, Servlet.init() for servlet [dispatcher] threw exception HTTP 状态 500 - servlet spring-dispatcher 的 Servlet.init() 抛出异常 - HTTP Status 500 - Servlet.init() for servlet spring-dispatcher threw exception HTTP状态500-servlet弹簧分配器的Servlet.init()抛出exception_(spring-dispatcher-servlet很好) - HTTP Status 500 - Servlet.init() for servlet spring-dispatcher threw exception_(spring-dispatcher-servlet is good) Servlet弹簧调度程序的Servlet.init()抛出异常(XmlBeanDefinitionStoreException) - Servlet.init() for servlet spring-dispatcher threw exception(XmlBeanDefinitionStoreException) Servlet Spring-Dispatcher的Servlet.init()引发异常3 - Servlet.init() for servlet spring-dispatcher threw exception 3 HTTP状态500-Servlet Dispatcher的Servlet.init()抛出异常 - HTTP Status 500 - Servlet.init() for servlet Dispatcher threw exception HTTP 状态 500 – servlet [telusko] 的内部服务器错误消息 Servlet.init() 抛出异常 - HTTP Status 500 – Internal Server Error Message Servlet.init() for servlet [telusko] threw exception MVC SPRING HTTP状态500-servlet mvc-dispatcher的Servlet.init()抛出异常 - MVC SPRING HTTP Status 500 - Servlet.init() for servlet mvc-dispatcher threw exception “ HTTP状态500-Servlet的Servlet.init()引发了异常” - “HTTP Status 500 - Servlet.init() for servlet spring threw exception” 错误:HTTP状态500 - servlet Spring_Test的Servlet.init()抛出异常? - Error: HTTP Status 500 - Servlet.init() for servlet Spring_Test threw exception?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM