内部服务器错误(Spring MVC 4.0)

时间:2018-07-07 10:28:13

标签: spring-mvc netbeans-8

我正在使用Spring MVC Framework,而我一直使用的IDE是NetBeans。自上周整周以来,我一直面临问题,这使我心烦意乱,现在我正站在世界前列(希望今天晚上我会面带微笑上床睡觉)。这是Snapshot of Project Structure

index.jsp

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>WELCOME</title>
    </head>

    <body>
        <form action = "AddNumbersFunction">

            <table>
                <tr>
                    <td> First Number: </td>
                    <td> <input type = "text" name = "num1"> </td>
                </tr>
                <tr>
                    <td> Second Number: </td>
                    <td> <input type = "text" name = "num2"> </td>
                </tr>
                <tr>
                    <td></td>
                    <td> <input type = "submit" name = "SubmitButton" value = "Add Numbers"> </td>
                </tr>
            </table>

        </form>
    </body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">

    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>

    <servlet>
        <servlet-name>MainCtrl</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>MainCtrl</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

MainCtrl-servlet.xml

<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?xml version="1.0" encoding="UTF-8"?> -->
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"

       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd" xmlns:context="http://www.springframework.org/schema/context">


    <ctx:annotation-config></ctx:annotation-config>
    <ctx:component-scan base-package = "com.MAKaey"></ctx:component-scan>

    <bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name = "prefix">/WEB-INF/jsp</property>
        <property name = "suffix">.jsp</property>
    </bean>

</beans>

AddController.java

package com.MAKaey;

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

@Controller
public class AddController {

    @RequestMapping("/AddNumbersFunction")
    public void add(){

        System.out.println("I'm Here!");
    }
}

问题是当我运行项目时,出现以下错误(javax.servlet.ServletException)Exception's Snapshot     甚至不显示任何文本字段,因为在您运行项目时,显示的第一页就是该错误。     请帮助我!谢谢!

1 个答案:

答案 0 :(得分:0)

更改

<ctx:annotation-config></ctx:annotation-config> <ctx:component-scan base-package = "com.MAKaey"></ctx:component-scan>

<tx:annotation-config></tx:annotation-config>
<tx:component-scan base-package = "com.MAKaey"></tx:component-scan>

因为您是在此处使用xmlns:tx="http://www.springframework.org/schema/tx"进行导入