namratakakkar84 -1 Newbie Poster

Hi I have made a program in which a servlet page is called by html page. The problem is that whenevr control goes on to servlet page it shows that the servlet page does not exist.
I am deploying my application on tomcat and I am using MS-ACCESS as database.
The html code is:

<html>
<head>
<title> login </title>

<script language="javascript">
function validatename()
{
var field1=document.form4.ac;
var field2=document.form4.pass;
var pass_len=6;
var pass_val=document.form4.pass.value;
var act_len=pass+val.length;

if(document.form4.ac.value==")
{
alert:"enter account name");
field1.focus();
return false;
}

else
{
if(act_len<pass_len)
{
alert("password field cannot be left blank");
field2.focus();
return false;
}
else
{
alert("password cannot less than six characters");
field2.focus();
return false;
}
}
}
</script>
</head>
<h1> Login here!!!!!!!! </h1>
<form id="form4" name="form4" method="post" onSubmit="return validatename(form4)" action="/LOGIN">
Account <input type="text" name="ac"/>
Password <input type="password" name="pass"/>
<input name="login" type="submit" value="login"/>
<input name="reset" type="reset" value="reset"/>
</form>


the servlet code is:

package com.pack;

import java.io.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;


public class LOGIN extends HttpServlet{

public void doPost(HttpServletRequest req, HttpServletResponse res) 
           throws ServletException,IOException
{

res.setContentType("text/html");
PrintWriter out=res.getWriter();
String account=req.getParameter("ac");
String password=req.getParameter("pass");

try
{

String url="Jdbc:Odbc:Namrata";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(url);
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from database1 where Account="+account+" and Password="+password);
if(rs.next()==false)
{
res.setContentType("text/html");
res.setStatus(HttpServletResponse.SC_OK);
out.println("<br><br>unknown user");
out.println("<html><head><title>checking the login</title></head>");
out.println("<h2>unknown user.............access denied</h2>");
out.println("<a href='login.html'>back</a></body></html>");
}
else
{
res.sendRedirect("welcome.html");
}
con.close();
}

catch(Exception e)
{
out.println("the exception is"+e);
}
}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.