404用于将jsp导航到servlet

时间:2018-05-30 12:43:37

标签: javascript java jsp servlets

我正在尝试使用jspjava scriptservlet创建一个简单的Web应用程序。应用程序的前端工作正常,但点击提交,我得到了

  

404错误,即:找不到资源

XML文件对我来说似乎很好。我不知道我缺少的地方。我尝试了很多,但都失败了。请提前获取所有帮助。

jsp page

<%@ 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>  

0 个答案:

没有答案