Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 警告:在名为';dispatcherservlet';_Java_Xml_Spring_Spring Mvc_Spring Annotations - Fatal编程技术网

Java 警告:在名为';dispatcherservlet';

Java 警告:在名为';dispatcherservlet';,java,xml,spring,spring-mvc,spring-annotations,Java,Xml,Spring,Spring Mvc,Spring Annotations,我看到了类似的问题,并尝试将URL从/*映射到/但它不起作用。 我还试着直接从浏览器中点击URL,但也不起作用。 我刚到春天,有人能帮我吗 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>Arc

我看到了类似的问题,并尝试将URL从/*映射到/但它不起作用。 我还试着直接从浏览器中点击URL,但也不起作用。 我刚到春天,有人能帮我吗

    <!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <servlet>
    <servlet-name>dispatcherservlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!-- <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value></param-value>
    </init-param> -->
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>dispatcherservlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>
my index.jsp作为欢迎文件

 <html>
<body>
<h2>Hello World!</h2>
<form action="add">
<input type="text" name="first number">first number<br>
<input type="text" name="second number">second number<br>
<input type="submit" name="add two numbers"><br>

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

你好,世界!
第一个号码
第二个号码


当我运行时,我可以提交并点击add方法的URL,但我收到警告:在名为'DispatcherServlet'的DispatcherServlet中找不到URI为[/mvc/add]的HTTP请求的映射
您在
DispatcherServlet servlet.xml上缺少
,这将启用
@Controller
注释。

添加到
dispatcherservlet servlet.xml
请写下此答案,这样您将获得一些声誉。这解决了我的问题,谢谢。好的,很高兴帮助你!
    package com;

import javax.annotation.Resource;

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

@Controller
public class addition {

    @RequestMapping("/add")
 void add() {
     System.out.println("im addint");
 }
}
 <html>
<body>
<h2>Hello World!</h2>
<form action="add">
<input type="text" name="first number">first number<br>
<input type="text" name="second number">second number<br>
<input type="submit" name="add two numbers"><br>

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