index.jsp
---------------------------------------------------------------------------------------------------------------
<form id="form_911240" class="appnitro" method="post" action="ValidateUser.jsp">
<div class="form_description">
<h2>Inicio de Sesion</h2>
<p></p>
</div>
<ul >
<li id="li_1" >
<label class="description" for="element_1">Usuario </label>
<div>
<input id="element_1" name="uname" class="element text small" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_2" >
<label class="description" for="element_2">Contraseña </label>
<div>
<input id="password" name="pass" class="element text small" type="password" maxlength="255" value=""/>
</div>
</li>
<li class="buttons">
<input type="hidden" name="form_id" value="911240" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Ingresar" />
</li>
</ul>
</form>
-----------------------------------ValidateUser.jsp-------------------------------------------------
<%@ page import ="java.sql.*" %>
<%
String userid = request.getParameter("uname");
String pwd = request.getParameter("pass");
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/yourBDName",
"root", "root");
Statement st = con.createStatement();
ResultSet rs;
rs = st.executeQuery("select * from user where uname='" + userid + "' and pass='" + pwd + "'");
if (rs.next()) {
session.setAttribute("userid", userid);
response.sendRedirect("menu.jsp");
} else {
response.sendRedirect("errorLogin.jsp");
}
%>
</body>
</html>
//se necesita el Driver MYSQL
1 Response
Write a comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.