springMVC HTTP 500错误的Apache

在这里输入图像说明

上面是我的程序的目录层次结构

我是新来的spring和学习MVC的概念,我写了一个程序,其中input(名称)到一个文本框,并打印你好…'名称'。 以下是我的目录结构和我创build的各种文件。

web.xml中

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <display-name>MVC_HelloWorld</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- default configuration --> <servlet> <servlet-name>HelloWorld</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>hello</servlet-name> <url-pattern>*.ap</url-pattern> <!-- this same extension should bbe used in form action --> </servlet-mapping> </web-app> 

的HelloWorld-servlet.xml中

 <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"> <beans> <!-- default handler mapping --> <!-- file should be created under web inf annd it's view resolver file --> <!-- handler(Not rqd in case of default handler) --> <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" /> <!-- controller configuration --> <bean name="/HelloWorld.ap" class="controller.HelloController"> <!-- mapping url pattern to controller class using 'name' --> <!-- view resolver --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" vlaue="/"/> <!-- default location (prefix used foor rqd page locations) --> |<property name="sufix" value=".jsp"/> <!-- sufix used forr rqd page extensions --> </bean> </bean> </beans> 

HelloController.java

 package controller; import java.util.HashMap; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; import com.sun.javafx.collections.MappingChange.Map; public class HelloController implements Controller { @Override public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse res) throws Exception { String name=req.getParameter("name"); Map m= new HashMap(); // creating output object m.put("msg","Hello..."+name); ModelAndView mav=new ModelAndView("success"+m); return mav; } } 

的index.jsp

 <h1> Hello World</h1> <form action="./hello.ap"> NAME: <input type="text" name="name"> <input type="Submit" value="Say Hello"> </form> 

的success.jsp

 ${msg} 

当我运行这个代码时,index.jsp页面在进一步执行时正常运行。它显示了错误404.代码有什么问题? 我在使用Eclipse的氧气Apache 8.5

    您定义的servlet名称是HelloWorld但是在映射servlet中是hello 。 这些名称必须相同。

     <servlet> <servlet-name>HelloWorld</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>hello</servlet-name> <url-pattern>*.ap</url-pattern> <!-- this same extension should bbe used in form action --> </servlet-mapping> </web-app> 

    在这里你已经使用HelloWorld作为servlet的名字,并且你在后面提到的那个是不正确的,所以请更正一下,把servelt-mapping中的hello改成HelloWorld,然后作为HelloWorld.ap访问servlet。