Servlets Net4india服务器中的内部服务器错误

Servlets Net4india服务器中的内部服务器错误,servlets,Servlets,为了部署该项目,我在www.net4.in上购买了java server online,并使用他们提供的phpmyadmin访问权限创建了数据库。我已通过传输项目的.war文件部署了该项目 我已经调整了所有链接,如: servlet路径 表单提交路径 web.xml 所有必需的 在servlet路径中,如果我向servlet添加.java,它会在线显示代码,但是当我将表单提交到servlet时,相同的路径会出现错误 客户详细信息-填写客户详细信息 帐号 中心号码 提交 Servlet

为了部署该项目,我在www.net4.in上购买了java server online,并使用他们提供的phpmyadmin访问权限创建了数据库。我已通过传输项目的.war文件部署了该项目

我已经调整了所有链接,如:

  • servlet路径
  • 表单提交路径
  • web.xml
  • 所有必需的
在servlet路径中,如果我向servlet添加
.java
,它会在线显示代码,但是当我将表单提交到servlet时,相同的路径会出现错误



客户详细信息-填写客户详细信息 帐号 中心号码
提交
Servlet代码

package com.mayuri.servlet;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

/**
 * Servlet implementation class FileUploadDBServlet
 */
//@WebServlet("/FileUploadDBServlet")
@MultipartConfig(maxFileSize = 10177215) // upload file's size up to 16MB
public class SelectCustServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public SelectCustServlet() {
        super();
    }

    private String dbURL = "jdbc:mysql://118.67.244.52/databasename";
    private String dbUser = "loginid";
    private String dbPass = "pwd";

    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        Connection conn = null; // connection to the database
        PrintWriter out = response.getWriter();
        String message = null;  // message will be sent back to client
        try {

            DriverManager.registerDriver(new com.mysql.jdbc.Driver());
            conn = DriverManager.getConnection(dbURL, dbUser, dbPass);

            // gets values of text fields
            String Ac_No = request.getParameter("Ac_No");
            System.out.println("in Servlettttttttttttttttttttttttt" + Ac_No);

            String Center_No = request.getParameter("Center_No");

            try {
                // connects to the database

                // constructs SQL statement
                String sql = "INSERT INTO cust (Ac_No, Center_No ) values (?,?)";
                PreparedStatement statement = conn.prepareStatement(sql);

                statement.setString(1, Ac_No);
                statement.setString(2, Center_No);

                out.println("dfsfsdf");

                // sends the statement to the database server
                int row = statement.executeUpdate();
                if (row > 0) {
                    //                message = "File uploaded and saved into database";
                }

            } catch (SQLException ex) {
                message = "ERROR: " + ex.getMessage();
                ex.printStackTrace();
            }
        } catch (SQLException ex) {
            message = "ERROR: " + ex.getMessage();
            ex.printStackTrace();
        } finally {
            if (conn != null) {
                // closes the database connection
                try {
                    conn.close();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
            }

            // sets the message in request scope
            // request.setAttribute("Message", message);

            // forwards to the message page
            //request.getRequestDispatcher("Message.jsp").forward(request, response);
        }
    }
}
web.xml


软件MATCS
选择custservlet
选择custservlet
db.src.com.mayuri.servlet.SelectCustServlet
选择custservlet
../../src/com/mayuri/servlet/SelectCustServlet

使用简短有效的Servlet URL模式,不要忘记在表单操作前面加上上下文根路径前缀。Servlet URL模式显示在浏览器URL中

使用JSP表达式语言
${pageContext.request.contextPath}
或核心标记库获取上下文根相对URL路径


例如:

JSP:


web.xml:

<servlet>
    <servlet-name>SelectCustServlet</servlet-name>
    <servlet-class>db.src.com.mayuri.servlet.SelectCustServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>SelectCustServlet</servlet-name>
    <url-pattern>/myServlet</url-pattern>
</servlet-mapping>
<?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"
         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         id="WebApp_ID" version="2.5">

    <display-name>softwarematcs</display-name>
    <servlet>
        <description></description>
        <display-name>SelectCustServlet</display-name>
        <servlet-name>SelectCustServlet</servlet-name>
        <servlet-class>com.mayuri.servlet.SelectCustServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>SelectCustServlet</servlet-name>
        <url-pattern>/SelectCustServlet</url-pattern>
    </servlet-mapping>
</web-app>

选择custservlet
db.src.com.mayuri.servlet.SelectCustServlet
选择custservlet
/myServlet

请尝试以下代码。我已将web.xml修改为正确的
servlet类
name
com.mayuri.servlet.SelectCustServlet
,并将servlet的
url模式
修改为
/SelectCustServlet

此外,我还将HTML表单的
操作
更新为正确的servlet url模式

HTML格式:

<html>
    <body>
        <form id="theForm" name="form1" method="post" action="<%=request.getContextPath()%>/SelectCustServlet"  enctype="multipart/form-data" target="_self" onSubmit="return verify()">
            <fieldset class="login"><br>
                <legend>Customer Details - Fill Customer Details</legend>
                <div>
                    <label for="Ac_No">Account Number</label>
                    <input type="text" id="Ac_No" name="Ac_No" autocomplete="off" onKeyPress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;" />
                </div>

                <div>
                    <label for="Center_No">Center Number</label> <input type="text" id="Center_No" autocomplete="off" class="input username" name="Center_No"  onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"   />
                </div>
            </fieldset><br>
            <center>
                <button type="submit" >Submit</button>
            </center>
        </form>
    </body>
</html>


客户详细信息-填写客户详细信息 帐号 中心号码
提交

web.xml:

<servlet>
    <servlet-name>SelectCustServlet</servlet-name>
    <servlet-class>db.src.com.mayuri.servlet.SelectCustServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>SelectCustServlet</servlet-name>
    <url-pattern>/myServlet</url-pattern>
</servlet-mapping>
<?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"
         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         id="WebApp_ID" version="2.5">

    <display-name>softwarematcs</display-name>
    <servlet>
        <description></description>
        <display-name>SelectCustServlet</display-name>
        <servlet-name>SelectCustServlet</servlet-name>
        <servlet-class>com.mayuri.servlet.SelectCustServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>SelectCustServlet</servlet-name>
        <url-pattern>/SelectCustServlet</url-pattern>
    </servlet-mapping>
</web-app>

软件MATCS
选择custservlet
选择custservlet
com.mayuri.servlet.SelectCustServlet
选择custservlet
/选择custservlet

您看到的错误是什么?表单操作没有指向正确的Servlet URL模式。在web.xml中为该servlet定义一个有效的URL,然后使用它保持URL模式简短且有意义,并且不要违背其目的。不要向所有人透露包结构。它应该只为开发人员和部署人员所知。