Я пытаюсь создать одно простое веб-приложение, используя jsp, java script, servlet. Интерфейс приложения работает нормально, но, нажав на кнопку "Отправить", я получаю
404 error i.e:resource not found
XML-файл мне кажется нормальным, я не знаю, где мне не хватает. Я много пробовал, но не получилось. Заранее благодарю за помощь.
<%@ 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>
<link
href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel = "stylesheet">
<script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script type='text/javascript' src='Validate.js'></script>
<link rel='stylesheet' type='text/css' href='stylesheet.css' />
<script type = "text/javascript"
src = "http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type = "text/javascript"
src = "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>
<title>Invoice Generator</title>
</head>
<body>
<form name = "myform" action = "servlet/Register" method = "get" onsubmit = "return validateform()">
<table>
<tr>
<td class = "tdLabel"><label for = "ShopNr" class = "label">Invoice
To ShopNr*:</label></td>
<td><input type = "text" name = "Invoice_to_ShopNr" value = ""
id = "ShopNr" style = "width: 160px" /></td>
</tr>
<tr>
<td class = "tdLabel"><label for = "datefrom" class = "label">Date
From*:</label></td>
<td><input type = "text" name = "datefrom" value = "" id = "datefrom"
placeholder = "MM/DD/YYYY" style = "width: 160px" /></td>
</tr>
<tr>
<td class = "tdLabel"><label for = "dateto" class = "label">Date
To*:</label></td>
<td><input type = "text" name = "dateto" value = "" id = "dateto"
placeholder = "MM/DD/YYYY" style = "width: 160px" /></td>
</tr>
<tr>
<td class = "tdLabel"><label for = "File_name" class = "label">File
Name*:</label></td>
<td><input type = "text" name = "FileName" value = "" id = "File_name"
style = "width: 160px" /></td>
</tr>
</table>
<button type = "submit">Submit</button>
</form>
</body>
</html>
==========================
java script
============
$(document)
.ready(
function() {
$("#datefrom").datepicker({
closeOnDateSelect : false,
closeOnTimeSelect : true,
initTime : true,
format : 'd-m-Y H:m',
minDate : '01/01/2012',
maxDate : '0',
roundTime : 'ceil',
});
$("#dateto").datepicker({
closeOnDateSelect : false,
closeOnTimeSelect : true,
initTime : true,
format : 'd-m-Y H:m',
maxDate : '0',
roundTime : 'ceil',
});
$("button")
.click(
function() {
var datefrom = $("#datefrom").val();
var dateto = $("#dateto").val();
var df = Date.parse(datefrom);
var dto = Date.parse(dateto);
var shop_Num = $("#ShopNr").val();
var Filename = $("#File_name").val();
var fieldNum = /^[a-z]+$/i;
if (shop_Num === "")
{
alert("Invoice To ShopNr can not be blank");
} if (shop_Num === 0) {
alert("Invoice To ShopNr can not be 0");
} if (!(shop_Num > 0 && shop_Num < 999999)) {
alert("Invoice To ShopNr must be in the range of 1 to 999999");
} if (datefrom === ""
|| dateto === "") {
alert("Please fill all the date fields.");
} if (df > dto) {
alert("Date-from should be before Date-to field");
} if ((dto - df) > "15552000000") {
alert("Interval between Date-from and Date-to field should not be more than 6 months");
} if (Filename == "") {
alert("Please fill the File Name")
} if (!(Filename.match(fieldNum))) {
alert("File Name accept only letters");
}
if ( (shop_Num == "" || shop_Num == null) ||(shop_Num == 0)|| (!(shop_Num > 0 && shop_Num < 999999))||(dateto == "" || dateto == null)
||(df > dto)||((dto - df) > "15552000000")|| (datefrom == "" || datefrom == null) || (Filename == "" || Filename == null))
{
return false;
}
else {
confirm("Do you want to submit");
return true;
}
});
});
=================================
Servlet
=====================================
import java.io.*;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
public class Register extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String n=request.getParameter("Invoice_to_ShopNr");
String p=request.getParameter("datefrom");
String e=request.getParameter("dateto");
String c=request.getParameter("FileName");
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521/orcl","system","system");
PreparedStatement ps=con.prepareStatement(
"insert into registeruser1 values(?,?,?,?)");
ps.setString(1,n);
ps.setString(2,p);
ps.setString(3,e);
ps.setString(4,c);
int i=ps.executeUpdate();
if (i>0)
out.print("You are successfully registered...");
}catch (Exception e2) {System.out.println(e2);}
out.close();
}
}
=======================
web.xml
=============================
<web-app>
<servlet>
<servlet-name>Register</servlet-name>
<servlet-class>Register</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Register</servlet-name>
<url-pattern>/servlet/Register</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>NewFile.jsp</welcome-file>
</welcome-file-list>
</web-app>
а ваш сервлет в пакете?
пожалуйста, какой URL вы используете для страницы формы?
@JonathanLaliberte URL-адрес браузера -локальный: 8080 / первый_сервлет / NewFile.jsp, а пакет сервлета является «пакетом по умолчанию» в исходной папке.
тогда first_servlet - это имя вашего приложения? Кроме того, есть сервлет в пакете?
@JosephPeter url для страницы формы означает браузер или xml?
@JonathanLaliberte first_servlet - это имя динамического веб-проекта. Да, сервлет находится в пакете по умолчанию в исходной папке.
Как называется пакет по умолчанию, в котором находится ваш сервлет?
@JonathanLaliberte это то же имя, т.е .: пакет по умолчанию
Я мог отлаживать свой код, теперь он у меня работает. Ошибка была в файле jsp. В действии = "сервлет / регистр" было ошибкой. Это должно быть просто "/Register". Тогда все работало нормально



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


перед отправкой формы, какой текущий URL-адрес отображается в браузере?