gpt4 book ai didi

java - 我总是在 Spring mvc 应用程序中收到 Getting HTTP-404 错误

转载 作者:行者123 更新时间:2023-12-02 12:17:18 24 4
gpt4 key购买 nike

我正在尝试开发我的第一个 spring mvc 应用程序并收到上述错误。我搜索了十几个相同异常的解决方案,但找不到任何解决方案。

这是我的 web.xml

  <servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

mvc-dispatcher-servlet.xml 文件

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

<context:component-scan base-package="m"/>
<mvc:default-servlet-handler />


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

</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>

index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="/Hello.ds">
NAME : <input type="text" name="hello">
<input type="submit" value="OK">
</form>
</body>
</html>

Controller

@org.springframework.stereotype.Controller
public class jnk {
@RequestMapping("/Hello")
public ModelAndView handleRequest(HttpServletRequest r,HttpServletResponse res) throws Exception{

String name=r.getParameter("name");
ModelAndView m=new ModelAndView("success");
m.addObject("MSG", name);
return m;
}

}

我的jsp文件位于WEB-INF/下目录

包名称是:m

最佳答案

Controller 公开一个名为 /Hello 的映射(请参阅: @RequestMapping("/Hello") )但您的表单正在尝试提交到 /Hello.ds (参见<form action="/Hello.ds">)。

关于java - 我总是在 Spring mvc 应用程序中收到 Getting HTTP-404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46074791/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com