Java 404运行jsp时出错
嗨,我在提交下面的jsp时收到404HTTP状态 HTTP状态404-/TestServlet1 你能帮我解决这个错误吗 注:定义了人和狗类 index.jspJava 404运行jsp时出错,java,jsp,servlets,Java,Jsp,Servlets,嗨,我在提交下面的jsp时收到404HTTP状态 HTTP状态404-/TestServlet1 你能帮我解决这个错误吗 注:定义了人和狗类 index.jsp <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <html> <head> </head> <body> <form
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>
</head>
<body>
<form id="a" action="/TestServlet1">
<input type="submit">
</form>
<%
%>
Name = '${person.name}'
Dog = '${person.dog.name}'
</body>
</html>
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>GlobalWeather</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>test.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/TestServlet1</url-pattern>
</servlet-mapping>
</web-app>
全球天气
index.jsp
TestServlet
test.TestServlet
TestServlet
/TestServlet1
404表示找不到URL。我怀疑您的URL中需要web应用程序名称
因此,不要使用以下形式的动作:
/TestServlet1
试一试
只需在您的表单操作中删除tha/即可:
<form id="a" action="/TestServlet1">
换成
<form id="a" action="TestServlet1">
在HTML中,添加/表示相对URL,没有斜杠表示绝对URL。或者最好使用此处提到的上下文:
<form id="a" action=${pageContext.request.contextPath}/TestServlet1>
您必须将contextroot+servlet名称。。。 contextRoot通常是项目的名称
action="/nameProject/TestServlet1"
我希望这能帮助你第一个和第三个答案是正确的。写入action=“TestServlet1”或action=“/Projectname/TestServlet1”。如果将/testservlet1付诸实施,则意味着您正在指定所需文件的路径,在本例中,该路径是错误的;而如果将testservlet1付诸实施,则意味着您正在项目中搜索要运行的文件名testservlet1 你把index.jsp放在哪里了?什么文件夹?
<form id="a" action=${pageContext.request.contextPath}/TestServlet1>
action="/nameProject/TestServlet1"