這是index.jsp檔案
。<html>
<body>
<form action="add">
<input type="text" name="t1"> </br>
<輸入型別="text" name="t2"></br>
<輸入型別="submit">
</form>
</body>
</html>
這是todo-servlet.xml
。<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"?
xmlns:mvc="http://www.springframework.org/schema/mvc"?
xmlns:context="http://www.springframework.org/schema/context"。
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/span>
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">。
<context:component-scan base-package="com.telusko"> </context:component-scan>
<mvc:annotation-driven />
<mvc:annotation-driven enable-matrix-variables="true"/>
</beans>
web.xml檔案 ->/p>
<! 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>todo</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>todo</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
AddController.java檔案
package com.telusko;
import org.springframework.stereotype.Controller。
import org.springframework.web.bind.annotation.RequestMapping;
public class AddController {
public String add() {
return "display.jsp"/span>。
}
}
我所面臨的錯誤
HTTP Status 404 - Not Found
型別 狀態報告
描述 原生服務器沒有找到目標資源的當前代表,或者不愿意透露其存在。
Apache Tomcat/10.0.10。
在給出輸入后,錯誤顯示出來了,但錯誤顯示。我也嘗試了堆疊溢位上的其他解決方案,但都沒有成功。我使用spring mvc 4,并使用了一些youtube視頻。
uj5u.com熱心網友回復:
嘗試在html表單的action屬性中添加"/"
<form action="/add"/span>>
uj5u.com熱心網友回復:
你沒有在控制器中的類上面提到@path。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/313480.html
標籤:
