当运行一个简单的Java web应用程序时,我在我的网页中得到Http状态404 not found error
下面我上传了Servlet、JSP和.xml文件。我已经做了一些研究,并通过查看之前在本网站上发布的与我的问题相关的问题进行了更改。但仍然出现错误 index.jsp 当输入数据后单击提交时,它会进入localhost:8080/selectcar页面并显示404 not found。我想我在xml版本中犯了一些错误,但无法将其锁定。我使用的是glass fish server 4.0。。当运行一个简单的Java web应用程序时,我在我的网页中得到Http状态404 not found error,java,xml,jsp,servlets,Java,Xml,Jsp,Servlets,下面我上传了Servlet、JSP和.xml文件。我已经做了一些研究,并通过查看之前在本网站上发布的与我的问题相关的问题进行了更改。但仍然出现错误 index.jsp 当输入数据后单击提交时,它会进入localhost:8080/selectcar页面并显示404 not found。我想我在xml版本中犯了一些错误,但无法将其锁定。我使用的是glass fish server 4.0。。 感谢您的帮助将jsp页面放在正确的位置,即WEB-INF文件夹中 结构应该是这样的 src -您的serv
感谢您的帮助将jsp页面放在正确的位置,即WEB-INF文件夹中 结构应该是这样的 src -您的servlet文件 网络应用 -WEB-INF -您的jsp页面是否使用“POST”方法进行测试?您只在servlet代码上实现了doPost
请参阅前面的答案:将您的CarServlet类放在web.XML中提到的正确位置。
文件夹应位于web inf/classes内
参考链接:这里有两种方法:
http://localhost:8080/app_name/index.jsp
。
在web.xml中,编辑行以在index.jsp之前包含“web-INF”
/WEB-INF/index.jsp
现在,您可以通过url直接访问index.jsphttp://localhost:8080/app_name
要访问servlet,请使用完整的urlhttp://localhost:8080/app_name/selectcar
in标签当你得到404时,你想点击哪个地址?首先尝试访问localhost:8080,然后使用localhost:8080/application\u name/index.jsp,然后尝试你的localhost:8080/application\u name/selectcar——application\u name是你的项目调试和调试find@TirupathiRajulocalhost:8080/application\u name/index.jsp有效很好。localhost:8080/application\u name/selectcar pops http 404 error我的文件夹结构Myapplication-->网页-->web inf-->包含jsp和xml。。。。。。。我的应用程序-->源程序包-->com.car.select-->服务器我正在使用post方法
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="/selectcar">
<p align="center">PLEASE ENTER YOUR NAME AND SELECT DESIRED CAR</p>
<p align="center"> NAME -
<label for="nameText"></label>
<input type="text" name="nameText" id="nameText" />
</p>
<p align="center"> CAR -
<label for="selectCar"></label>
<select name="selectCar" id="selectCar">
<option>BMW</option>
<option>Benz</option>
<option>Audi</option>
<option>Ducati</option>
</select>
</p>
<p align="center">
<input type="submit" name="submit" id="submit" value="Submit" />
</p>
</form>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>car</servlet-name>
<servlet-class>com.car.select.CarServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>car</servlet-name>
<url-pattern>/selectcar</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
package com.car.select;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CarServlet extends HttpServlet {
@Override
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
response.setContentType("text/html");
String name=request.getParameter("nameText");
String car= request.getParameter("selectCar");
PrintWriter out= response.getWriter();
out.println(name + " " +car);
}
}