como criar uam seessão com jsp

<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<%
      try
      {
        Class.forName("com.mysql.jdbc.Driver");
		//out.println("Driver encontrado!");           
		Connection con = DriverManager.getConnection("jdbc:mysql://localhost/login","root","root"); 
		//out.println("Conexão realizada com sucesso!")
			
			if (request.getParameter("usuario") != null)
			{
				Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
	            ResultSet.CONCUR_READ_ONLY); 	
				ResultSet rs = st.executeQuery("select * from login where usuario = '"+
				request.getParameter("usuario")+"' and senha = '"+
				request.getParameter("senha")+"'");
			
				if (rs.next())
				{
				    response.sendRedirect("itens_cadastra.jsp");
				   
				   
				}   
				else
				   out.println("Acesso ao Sistema Negado!");   
			
			}		
				  		  
	  }
	  catch(ClassNotFoundException erroClass)
	  {
	     out.println("Classe Driver JDBC não foi localizado, erro = "+erroClass);
	  }
	  catch(SQLException erroSQL)
	  {
  	     out.println("Erro de conexão com o Banco de dados, erro = "+erroSQL);
	  }
%>

<form id="form1" name="form1" method="post" action="">
  <div align="center">
    <p> </p>
    <p> </p>
    <p> </p>
    <table width="196" border="1">
      <tr>
        <td colspan="2"><label>
          <div align="center">ACESSO AO SISTEMA<br />
          </div>
        </label></td>
      </tr>
      <tr>
        <td width="88">Usuário:</td>
        <td width="92"><label>
          <input name="usuario" type="text" id="usuario" size="10" />
        </label></td>
      </tr>
      <tr>
        <td>Senha:</td>
        <td><input name="senha" type="password" id="senha" size="10" /></td>
      </tr>
      <tr>
        <td><label>
          <input type="reset" name="limpar" id="limpar" value="Limpar" />
        </label></td>
        <td><input type="submit" name="acesso" id="acesso" value="Acessar" /></td>
      </tr>
    </table>
  </div>
</form>
</body>
</html>

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source