java - The use of servlets and JSP -
i have created small application have problems in running piece of code in tomcat server 7. want create simple login page. have built database using mysql. form appeared correctly in browser, @ time press submit button 404 error. have used servlets , jsp. appreciate if taking in code below.
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 klienti username=? , password=? , 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 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>
my console shows error message
jul 25, 2016 2:48:40 pm org.apache.catalina.core.aprlifecyclelistener init info: apr based apache tomcat native library allows optimal performance in production environments not found on 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' 'org.eclipse.jst.jee.server:prorent' did not find 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 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
thank in advance!
your form submits data url /loginklientiservlet
don't have servlet mapping url pattern.
may can add url pattern in web.xml
have /listalog
. example,
<servlet-mapping> <servlet-name>loginklienti-dao</servlet-name> <url-pattern>/loginklientiservlet</url-pattern> </servlet-mapping>
Comments
Post a Comment