<!-- login.jsp -->
<Body>
<form action="loginAction.jsp" method="GET" name="login" >
<table border="1" style="border-collapse:collapse;" cellpadding="5px">
<tr>
<td>
<Strong>User Name:</strong>
<input type="text" name="username" id="username" size="30" maxlength="50" />
</td>
</tr>
<tr>
<td>
<Strong>Password: </strong>
<input type="password" name="password" id="password" size="30" maxlength="50" />
</td>
</tr>
<tr>
<td>
<input type="submit" id="submit" name="submit" value="Submit"></input>
<input type="reset" id="reset" name="reset" value="Reset"></input>
</td>
</tr>
</table>
</form>
</Body>
// ------------------------------------------------------------------------------------------------
<!-- loginAction.jsp -->
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.text.*"%>
<%
Statement st=null;
Connection con=null;
ResultSet rs=null;
// JDBC driver name and database URL
final String DB_URL = "jdbc:mysql://127.0.0.1:3306/test";
// Database credentials
final String DB_USER = "root";
final String DB_PASS = "public";
String user = request.getParameter("username");
String pass = request.getParameter("password");
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(DB_URL,DB_USER,DB_PASS);
st = con.createStatement();
String QueryString = "select username,pass from auth where username='"+user+"' and pass = '"+pass+"'";
rs = st.executeQuery(QueryString);
if(rs.next()){
out.print("Login Successfully.");
}
else
out.print("User Name and password are not Valid..");
}
catch (Exception e){
out.print(e);
}
finally{
st.close();
rs.close();
con.close();
}
%>
i am using your code in spring mvc..
ReplyDeletein jsp file how to transfer a if condition statement to spring controller mapping file..
not run
ReplyDeletenot running correctly
ReplyDelete