2016-07-25 13 views
0

私はすでに小さなアプリケーションを作成しましたが、Tomcatサーバー7でコードを実行する際に問題があります。単純なログインページを作成したいと思います。 MySQLを使用してデータベースを構築しました。私のフォームはブラウザに正しく表示されますが、私が送信ボタンを押すと、404エラーが表示されます。サーブレットとJSPを使用しています。誰かが私のコードを見ていると私はそれを感謝します。サーブレットとJSPの使用

LoginKlientiServlet.java:

package prorent.controllers; 
    import java.io.IOException; 
    import java.io.PrintWriter; 
    import java.sql.DriverManager; 
    import java.sql.ResultSet; 
    import java.sql.SQLException; 

import javax.servlet.RequestDispatcher; 
import javax.servlet.ServletException; 
import javax.servlet.annotation.WebServlet; 
//import javax.servlet.annotation.WebServlet; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
import javax.servlet.http.HttpSession; 

import com.mysql.jdbc.Connection; 
import com.mysql.jdbc.PreparedStatement; 
import java.io.*; 
import javax.servlet.http.*; 
import javax.servlet.*; 
import java.sql.*; 


import prorent.DAO.LoginKlientiDAO; 
//@(name="LoginKlientiServlet", urlPatterns= {"/LoginKlientiServlet"}) 
public class LoginKlientiServlet extends HttpServlet{ 

private static final long serialVersionUID = 1L; 

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
    response.setContentType("text/html"); 
    PrintWriter out = response.getWriter(); 
    String user = request.getParameter("username"); 
    String pass = request.getParameter("password"); 
    String repass = request.getParameter("repassword"); 
    try { 
     Class.forName("com.mysql.jdbc.Driver"); 
     Connection conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/pro", "root", "erida"); 
     PreparedStatement pst = (PreparedStatement) conn.prepareStatement("Select username,password, repassword from klienti where username=? and password=? and repassword=?"); 
     pst.setString(1, user); 
     pst.setString(2, pass); 
     pst.setString(2, repass); 
     ResultSet rs = pst.executeQuery(); 
     if (rs.next()) { 
      out.println("Correct login credentials"); 
     } 
     else { 
      out.println("Incorrect login credentials"); 
     } 
    } 
    catch (ClassNotFoundException | SQLException e) { 
     e.printStackTrace(); 
    } 
} 
} 

LoginKlientiDAO.java

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
pageEncoding="ISO-8859-1"%> 
<html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Login Application</title> 
</head> 
    <body> 
    <form action="LoginKlientiServlet" method="post"> 
    <fieldset style="width: 300px"> 
     <legend> Login to App </legend> 
     <table> 
      <tr> 
       <td>User ID</td> 
       <td><input type="text" name="username" required="required" /></td> 
      </tr> 
      <tr> 
       <td>Password</td> 
       <td><input type="password" name="password" required="required" /></td> 
      </tr> 
      <tr> 
       <td>Repassword</td> 
       <td><input type="password" name="repassword" required="required" /></td> 
      </tr> 
      <tr> 
       <td><input type="submit" value="Login" /></td> 
      </tr> 
     </table> 
    </fieldset> 
</form> 

web.xmlの

<?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:jsp="http://java.sun.com/xml/ns/javaee/jsp" 
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" 
metadata-complete="true" version="2.5"> 

<display-name>Jap me qera</display-name> 


<servlet> 

    <description /> 

    <display-name>LoginKlientiController</display-name> 

    <servlet-name>LoginKlienti-DAO</servlet-name> 

    <servlet-class>prorent.controllers.LoginKlientiServlet</servlet-class> 

</servlet> 



    <servlet-mapping> 

    <servlet-name>login-lista</servlet-name> 

    <url-pattern>/listalog</url-pattern> 



</servlet-mapping> 

私のコンソールは、このエラーメッセージ

 Jul 25, 2016 2:48:40 PM org.apache.catalina.core.AprLifecycleListener init 
    INFO: The APR based Apache Tomcat Native library which allows optimal  performance in production environments was not found on the java.library.path: C:\Program Files\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/bin/server;C:/Program Files/bin;C:/Program Files/lib/amd64;C:\Program Files\WinRAR;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\Skype\Phone\;C:\Users\USER\AppData\Local\Temp\Rar$EX59.800\eclipse;;. 
    Jul 25, 2016 2:48:40 PM org.apache.tomcat.util.digester.SetPropertiesRule begin 
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:prorent' did not find a matching property. 
Jul 25, 2016 2:48:40 PM org.apache.coyote.AbstractProtocol init 
INFO: Initializing ProtocolHandler ["http-bio-8080"] 
Jul 25, 2016 2:48:40 PM org.apache.coyote.AbstractProtocol init 
INFO: Initializing ProtocolHandler ["ajp-bio-8009"] 
Jul 25, 2016 2:48:40 PM org.apache.catalina.startup.Catalina load 
INFO: Initialization processed in 899 ms 
Jul 25, 2016 2:48:40 PM org.apache.catalina.core.StandardService startInternal 
INFO: Starting service Catalina 
Jul 25, 2016 2:48:40 PM org.apache.catalina.core.StandardEngine startInternal 
INFO: Starting Servlet Engine: Apache Tomcat/7.0.47 
Jul 25, 2016 2:48:41 PM org.apache.catalina.util.SessionIdGenerator createSecureRandom 
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [197] milliseconds. 
Jul 25, 2016 2:48:41 PM org.apache.coyote.AbstractProtocol start 
INFO: Starting ProtocolHandler ["http-bio-8080"] 
Jul 25, 2016 2:48:41 PM org.apache.coyote.AbstractProtocol start 
INFO: Starting ProtocolHandler ["ajp-bio-8009"] 
Jul 25, 2016 2:48:41 PM org.apache.catalina.startup.Catalina start 
INFO: Server startup in 1164 ms 

を示し、事前にありがとうございます!

答えて

0

フォームはデータをURL /LoginKlientiServletに送信しますが、そのURLパターンのサーブレットマッピングはありません。

/listalogのようにweb.xmlにURLパターンを追加することができます。例えば、

<servlet-mapping> 
    <servlet-name>LoginKlienti-DAO</servlet-name> 
    <url-pattern>/LoginKlientiServlet</url-pattern> 
</servlet-mapping> 
0

あなたのサーブレットマッピングは、デプロイメントディスクリプタ(web.xmlファイル)

にあなたがアプリケーションhere

修正するために、あなたのサーブレットをマップする方法についての詳細を知ることができます間違っているようですコードが見えるはずですsomethinfのように:

<servlet> 
    <servlet-name>LoginKlienti-DAO</servlet-name> 
    <servlet-path>prorent.controllers.LoginKlientiServlet</servlet-path> 
</servlet> 
<servlet-mapping> 
    <servlet-name>LoginKlienti-DAO</servlet-name> 
    <url-pattern>/LoginKlientiServlet</url-pattern> 
</servlet-mapping> 
+0

私はそれを試してみましたが、何も – Elly

+0

yを修正する必要があり、エラー – Elly

+0

であるように思わ変化しませんあなたのサーブレットクラスを指すサーブレットパス。サーブレットは 'prorent.controllers'パッケージに含まれていなければなりません。存在しない場合は、これを修正して正しいパッケージを選択する必要があります – MaVRoSCy

関連する問題