我正在尝试创建一个登录表单,但我的代码显示http 404错误,无法连接到mysql数据库。我无法解决问题。请查看代码并帮助我。
它也显示了这个错误 - tomcat的端口8080 reqrd已经在使用中
数据库连接文件
package connection;
import java.sql.*;
import java.io.*;
public class DataCon
{
Connection con;
public Connection getConnection1()
{
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance;
con = DriverManager.getConnection("jdbc:mysql://localhost/sumanDB","crime", "crime");
}
catch(Exception e)
{
e.toString();
}
return con;
}
public void close(Connection con)
{
try{
con.close();
}catch(Exception e1)
{}
}
}
Validate.jsp文件
<%@ page import="java.sql.*" %>
<%@ page import="connection.DataCon" %>
<%
Connection con=null;
Statement st=null;
ResultSet rs=null;
DataCon ds =new DataCon();
String uname=request.getParameter("UserName");
String pass=request.getParameter("Password");
System.out.println(uname);
System.out.println(pass);
try{
con=ds.getConnection1();
st=con.createStatement();
rs=st.executeQuery("select * from login_master where LOGIN_USER_NAME='"+uname+"'");
System.out.println("rs"+rs);
while(rs.next())
{
System.out.println("inside while");
String user1=rs.getString(1);
String password=rs.getString(5);
System.out.println(user1);
System.out.println(password);
if(uname.equals(user1)&&pass.equals(password))
{
System.out.println("inside if");
System.out.println(password);
String profile=rs.getString(2);
if(pass.equals(password))
{
System.out.println("inside pass equal");
if(profile.equals("PF1"))
response.sendRedirect("adminzone.jsp");
else if(profile.equals("PF2"))
response.sendRedirect("invgzone.jsp");
else if(profile.equals("PF3"))
response.sendRedirect("writerzone.jsp");
}
else
response.sendRedirect("Login.jsp");
}//if
else
response.sendRedirect("Login.jsp?msg='Incorrect Username or Password - Re-Check '");
}//while
}catch(Exception e){}
con.close();
%>