我正在制作一个简单的程序,只需输入几个字段作为输入,然后点击确认按钮后会出现confirm.jsp。
我创建了Controller.java servlet以识别单击的按钮,然后打开jsp。 Controller.java存储在目录WEB-INF / classes / ch2 / servletController中,submit.jsp,register.jsp,confirm.jsp存储在/ ch2 / servletController目录中。
每当我点击确认按钮时,我都会收到以下错误。 WebApplication是我的项目的名称。我正在使用netBeans IDE。
HTTP状态404 - / WebApplication / ch2 / servletController / Controller
输入状态报告
message / WebApplication / ch2 / servletController / Controller
说明请求的资源不可用。
请在下面找到web.xml,servlet和所有jsp文件..
register.jsp
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Register</title>
</head>
<body>
<form method="get" action="Controller">
<p><b>E-store</b></p>
<br>
<br>
<p>Enter First Name: <input type="text" name="FirstName" value="${param.FirstName}"></p>
<p>Enter Last Name: <input type="text" name="LastName" value="${param.LastName}"></p>
<p>Enter Mail-id: <input type="text" name="MailId" value="${param.MailId}"></p>
<p>Enter PhoneNo: <input type="text" name="PhoneNo" value="${param.PhoneNo}"></p>
<p><input type="submit" name="confirmButton" value="confirm"></p>
</form>
</body>
</html>
confirm.jsp
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Confirm Details</title>
</head>
<body>
<form method="get" action="Controller" >
<p><b>E-store</b></p>
<br>
<br>
<p>First Name: ${param.FirstName}<input type="hidden" name="FirstName" value="${param.FirstName}"></input></p>
<p>Last Name: ${param.LastName}<input type="hidden" name="LastName" value="${param.LastName}"></input></p>
<p>Mail-id: ${param.MailId}<input type="hidden" name="MailId" value="${param.MailId}"></input></p>
<p>PhoneNo: ${param.PhoneNo}<input type="hidden" name="PhoneNo" value="${param.PhoneNo}"></input></p>
<input type="submit" name="EditButton" value="Edit">
<input type="submit" name="Submitbutton" value="Submit">
</form>
</body>
</html>
submit.jsp
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Confirm Details</title>
</head>
<body>
<form>
<p><b>E-store</b></p>
<br>
<br>
<p>Thank You for the registration. Your details have been submitted as follows-</p>
<p>First Name: ${param.FirstName}<input type="hidden" name="FirstName" value="${param.FirstName}"></input></p>
<p>Last Name: ${param.LastName}<input type="hidden" name="LastName" value="${param.LastName}"></input></p>
<p>Mail-id: ${param.MailId}<input type="hidden" name="MailId" value="${param.MailId}"></input></p>
<p>PhoneNo: ${param.PhoneNo}<input type="hidden" name="PhoneNo" value="${param.PhoneNo}"></input></p>
</form>
</body>
</html>
Controller.java
package ch2.servletController;
import java.io.IOException;
import javax.servlet.http.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
public class Controller extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
String address=null;
if(request.getParameter("confirmButton")!= null)
{
address="confirm.jsp";
}
else if(request.getParameter("EditButton")!= null)
{
address="register.jsp";
}
else if(request.getParameter("Submitbutton")!=null)
{
address="submit.jsp";
}
RequestDispatcher Dispatcher=request.getRequestDispatcher(address);
Dispatcher.forward(request, response);
}
}
的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>FirstController</servlet-name>
<servlet-class>ch2.servletController.Controller</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FirstController</servlet-name>
<url-pattern>/Controller</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
的index.jsp
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>First JSP</title>
</head>
<body>
<form>
<p><b>Welcome to E-store</b></p>
<br>
<br>
<p>Click to <a href="ch2/servletController/register.jsp">Register</a></p>
</form>
</body>
</html>
如果有人能帮助我解决这个问题,我将不胜感激。
非常感谢提前。
答案 0 :(得分:1)
我必须将register.jsp
的位置更改为index.jsp
所在的网络目录,这对我有用。