Skip to main content

Posts

Showing posts with the label Servlet

Managing Session using Servlet session API

You can use the classes and interfaces defined in the Servlet Session API to create and manage user sessions. Various interfaces provided by Servlet Session API to create and manage user session are, javax.servlet.http.HttpSession, javax.servlet.http.HttpSessionListener, and javax.servlet.http.HttpSessionBindingListener. The javax.servlet.http.HttpSession interface provides methods for tracking the session of a user. You can create an object of HttpSession interface to store session information as name/value pairs. You can later retrieve this information to manage user sessions. httpservlet.html <!-- To change this template, choose Tools | Templates and open the template in the editor. --> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" > <html> <head> <title></title> <meta http-equiv= "Content-Type" content= "text/html; charset=UTF-8" > </head> <bod...

Managing Session using Cookies

Cookies are small text files that are stored by an application server in the client browser to keep track of all the users. A cookie has values in the form of name/value pairs. For example, a cookie can have a name, user with the value, Michael. They are created by the server and are sent to the client with the HTTP response headers. The client saves the cookies in the local hard disk and sends them along with the HTTP request headers to the server. A Web browser is expected to support 20 cookies per host and the size of each cookie can be a maximum of 4 bytes each. Various characteristics of cookies are: Coockie.html <!-- To change this template, choose Tools | Templates and open the template in the editor. --> <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" > < html > < head > < title ></ title > < meta http-equiv ="Content-Type" content ="text/html;...

Managing Session using URL rewriting

URL rewriting is a session management technique that manages user session by modifying a URL. Usually, this technique is used when information that is to be transferred is not very critical because the URL can be intercepted easily during transfer. For example, in an online shopping portal, a servlet can modify a URL to include user information, such as a username. The servlet can then display the URL. When the user clicks the URL hyperlink. The information is sent to another servlet that retrieves the user information and displays a welcome message. You can use the following code to create the servlet, RewriteServletURL that modifies and displays a URL. urlRewriting .html <!-- To change this template, choose Tools | Templates and open the template in the editor. --> <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" > < html > < head > < title ></ title > < meta ...

Managing Session using Hidden form field

You can use hidden form fields to maintain the session information of a user while the user interacts with the Web application. A hidden form field is embedded in an HTML page and is not visible when viewed in a browser. The following code snippet shows a hidden form field in an HTML page: Programs: HiddenForm.html <!-- To change this template, choose Tools | Templates and open the template in the editor. --> <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" > < html > < head > < title ></ title > < meta http-equiv ="Content-Type" content ="text/html; charset=UTF-8" > </ head > < body > < form action ="FirstServlet1" method ="post" > Name: < input type ="text" name ="uname" />< br /> < input type ="submit" value ="go" /> </ form > </ body > ...

Login form in servlet with Attribute & RequestDispatcher

login.html < html > < head > < title ></ title > < meta http-equiv ="Content-Type" content ="text/html; charset=UTF-8" > </ head > < body > < form method ="post" action ="login" > User Name: < input type ="text" name ="name" />< br /> Password: < input type ="password" name ="pass" />< br /> < input type ="submit" value ="login" /> </ form > </ body > </ html > login.java package Code; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * * @author Dilip */ public class login extends ...

Addition of Two Number using servlet and jsp

index.jsp <%@page contentType="text/html" pageEncoding="UTF-8"%> <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > < html > < head > < meta http-equiv ="Content-Type" content ="text/html; charset=UTF-8" > < title > JSP Page </ title > </ head > < body bgcolor ="yellow" > < center >< h1 > Addition of Two Number </ h1 ></ center > < form action =" additionservlet " method ="post" > < table border ="0" width ="100" align ="center" > < tr > < td > First Number </ td > < td >< input type ="text" name ="txtnum1" value ="" /></ td > ...

How to configure JNDI step by step in NetBeans..

  Software Version Required NetBeans IDE Java bundle, 6.8 or 6.9 Java Development Kit (JDK) version 6,7 GlassFish server v3 or Open Source Edition 3.0.1 SQL Server  2005 Type 4 Driver for SQL Server 2005 sqljdbc SQL Server 2005 Type 4 driver •First Download the SQL Server 2005 Type 4 driver. •Set the classpath Database Create a database and table in SQL Server 2005 Create a new web Application index.jsp code <%-- Document : index Created on : Nov 21, 2012, 3:42:17 PM Author : NIIT --%> <%@page contentType= "text/html" pageEncoding= "UTF-8" %> <!DOCTYPE html> <html> <head> <meta http-equiv= "Content-Type" content= "text/html; charset=UTF-8" > <title>JNDI DEMO</title> </head> <body bgcolor= "pink" > <h1>Login Management System...