Gadgets

Tuesday, 27 November 2012

Login Form Using HTML and CSS Styles

Login Form Using HTML and CSS Styles with good look

code :
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <style type="text/css">
            #textfield{
                margin: 0px;
              height: 20px;
              border: solid 1px  #d9d9d9;
             border-radius:2px;
          
            }
            #textfield:hover{
                border: solid 1px  cadetblue;
               -moz-box-shadow:  0 1px 2px rgba(0,0,0,0.2);
              
            }
            #textfield:focus
            {
               
                border: 1px solid  #4d90fe;
            
               -moz-box-shadow: 0 1px 2px rgba(0,0,0,0.2);
            }
            #button{
                height: 25px;
                color: whitesmoke;
                background-color: #4d90fe;
                border-radius:2px;
               
            }
            label{
                color:  #4d90fe;
            }
        </style>
    </head>
    <body>
        <table>
            <tr>
                <td><label>User id</label></td><td><input type="text" name="uid" value="" id="textfield" /></td>
            </tr>
             <tr>
                 <td><label>Password</label></td><td><input type="password" name="psw" value="" id="textfield" /></td>
            </tr>
             <tr>
                 <td></td><td><input type="submit" value="Sign in" id="button" /></td>
            </tr>
        </table>
    </body>
</html>

 output :


That text field color will be change to light blue after kept the cursor on text field  
 
This text field color will be changes to blue after clicked on the text field

Monday, 26 November 2012

Login form using jsp and servlet with sessions

Login form using jsp and servlet
this code is developed in netbeans
the RequestDispatcher interface provides the facility of dispaching the request to another resource it may html, jsp, and servlet
code for jsp :
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
       
        <title>user registration</title>
        <style type="text/css">
            body{
                margin-top: 100px;
              
            }
            #tf,select{
             border: solid 1px darkcyan; 
            }
            h2{
                color:  cornflowerblue;
                font-family: cursive;
            }
            #button{
                color: white;
                background-color:blue;
                border: sloid 1px #aaaaaa;
                cursor: pointer;
                width: 100px;
                height: 30px;
               
        
            }
        </style>
    </head>
    <body>
    <center>
        <h2>Sing In Here</h2>
        <form action="LoginServlet" method="post">
            <table>
               
                <tr>
                    <td>Email id </td><td><input type="text" name="mailid" value=""id="tf" /></td>
                </tr>
                <tr>
                    <td>Password </td><td><input type="password" name="psw" value="" id="tf"/></td>
                </tr>
              
                <tr><td></td><td><input type="submit" name=""value="Sign In" id="button"/></td></tr>
            </table>
        </form>
    </center>
    </body>
</html>
Servlet code :
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class LoginServlet extends HttpServlet {
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, ClassNotFoundException, SQLException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            String mid,psw;
            mid=request.getParameter("mailid");
            psw=request.getParameter("psw");
            Class.forName("com.mysql.jdbc.Driver");
            Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/myblog","narendar_blog","12345");
            String q="select * from account_info where mail_id='"+mid+"' and password='"+psw+"'";
            Statement st=con.createStatement();
            ResultSet rs=st.executeQuery(q);
            String tmid ="",tpsw="",tname="";
            while(rs.next()){
                tmid=rs.getString("mail_id");
                tpsw=rs.getString("password");
                tname=rs.getString("name");
            }
            if(mid.equals(tmid)&&psw.equals(tpsw)){
                HttpSession session=request.getSession(true);
                        session.setAttribute("mail_id", mid);
                        request.setAttribute("mail_id",mid);
                        request.setAttribute("name",tname);
              RequestDispatcher rd=request.getRequestDispatcher("account_home.jsp");
              rd.forward(request, response);
            }
        }
        catch(Exception e)
        {
            out.println(e);
        }finally {           
            out.close();
        }
    }

Sunday, 25 November 2012

Registration form using jsp with servlet

 This code is developed by using NetBeans. Here I include CSS styles also in JSP page
Code for jsp:
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">       
        <title>user registration</title>
        <style type="text/css">
            body{
                margin-top: 100px;              
            }
            #tf,select{
             border: solid 1px darkcyan; 
            }
            h2{
                color:  cornflowerblue;
                font-family: cursive;
            }
            #button{
                color: white;
                background-color:blue;
                border: sloid 1px #aaaaaa;
                cursor: pointer;
                width: 100px;
                height: 30px;        
            }
        </style>
    </head>
    <body>
    <center>
        <h2>Register Here</h2>
        <form action="RegServlet" method="post">
            <table>
                <tr>
                    <td>Name </td><td><input type="text" name="name" value="" id="tf" /></td>
                </tr>
                <tr>
                    <td>Email id </td><td><input type="text" name="mailid" value=""id="tf" /></td>
                </tr>
                <tr>
                    <td>Password </td><td><input type="password" name="psw" value="" id="tf"/>
                 </td>
                </tr>
                <tr>
               
                <td>Security Question </td>
                <td><select name="sq">
                        <option value="your best friend name">your best friend name</option>
                          <option value="your favorite movie">your favorite movie</option>
                           <option value="your favorite subject">your favorite subject</option>
                    </select></td></tr>
                <tr><td>Security Answer </td><td><input type="text" name="sa" value=""id="tf" />
           </td>
                </tr>
                <tr><td></td><td><input type="submit" name=""value="Register me" id="button"/>
            </td></tr>
            </table>
        </form>
    </center>
    </body>
</html>
Servlet code:
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class RegServlet extends HttpServlet {
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, ClassNotFoundException, SQLException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            String name,mid,psw,sq,sa;
           name=request.getParameter("name");
           mid=request.getParameter("mailid");
           psw=request.getParameter("psw");
           sq=request.getParameter("sq");
           sa=request.getParameter("sa");
           Class.forName("com.mysql.jdbc.Driver");
           Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/myblog",
           "narendar_blog","12345");
           String q=" insert into account_info values('"+name+"','"+mid+"','"+psw+"','"+sq+"',
           '"+sa+"')";
           Statement st=con.createStatement();
           int i=st.executeUpdate(q);
           if(i>0)
           {
            RequestDispatcher rd=request.getRequestDispatcher("account_login.jsp");
              rd.forward(request, response);
           }
        }
        catch(Exception e)
        {
            out.println(e);
        }finally {           
            out.close();
        }
    }

Friday, 23 November 2012

Web Search Engine Box

Web Search Engine Box using html and css styles :
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <style type="text/css">
            body{
                margin-top: 180px;
               text-align: center;
            }
            #tf{
             border: solid 2px darkcyan;
            }
            h1{
                color:  cornflowerblue;
                font-family: cursive;
                                                             }
            #button{
                color: white;
                background-color:blue;
                border: sloid 1px #aaaaaa;
                cursor: pointer;
                width: 60px;
                height: 25px;       
            }                       
            </style>
    </head>
    <body>
        <h1>Web Search</h1>
       <form name="cse"action="http://www.google.com/cse">
  <input name="q" type="text" size="45" id="tf" />
  <input type="submit" name="sa" value="Search" id="button" />
</form>
    </body>

</html>
output :