Hidden Form Field

Advertisements

Cookies Handling in Servlet URL Rewriting Servlet

Hidden Form Field

Tracking client conversion using Html hidden variables in secure manner is known as hidden form field.

How to use Hidden Form Field ?

In Hidden Form Field we are use html tag is <input type="hidden"> and with this we assign session ID value.

Syntax

<input type="hidden" name="uname" value="porter">

Hidden Form Field Advantage

  • Basic knowledge of html is enough to work with this technique.
  • It will always work whether cookie is disabled or not.
  • Hidden boxes resides in web pages of browser window so they do not provide burden to the server.
  • This technique can be used along with all kind of web server or application server.

Hidden Form Field Dis-Advantage

  • More complex than URL Rewriting.
  • It is maintained at server side.
  • Extra form submission is required on each pages.
  • Hidden form field can not store java object as values. They only store text value
  • It Also increase network traffic because hidden boxes data travels over the network along with request and response.
  • Hidden boxes does not provides data security because their data can be view through view source option.

Example of session tracking by using Hidden Form Field

index.html

<form action="servlet1">
Name:<input type="text" name="userName"/> <br/>
<input type="submit" value="continue"/>
</form>

FirstServlet.java

import java.io.*;  
import javax.servlet.*;  
import javax.servlet.http.*;  
  
public class FirstServlet extends HttpServlet {  
public void doGet(HttpServletRequest request, HttpServletResponse response){  
        try{  
  
        response.setContentType("text/html");  
        PrintWriter out = response.getWriter();  
          
        String n=request.getParameter("userName");  
        out.print("Welcome "+n);  
          
        //creating form that have invisible textfield  
        out.print("<form action='servlet2'>");  
        out.print("<input type='hidden' name='uname' value='"+n+"'>");  
        out.print("<input type='submit' value='continue'>");  
        out.print("</form>");  
        out.close();  
  
           }
		catch(Exception e){System.out.println(e);}  
    }  
}  

SecondServlet.java

import java.io.*;  
import javax.servlet.*;  
import javax.servlet.http.*;  
public class SecondServlet extends HttpServlet {  
public void doGet(HttpServletRequest request, HttpServletResponse response)  
        try{  
        response.setContentType("text/html");  
        PrintWriter out = response.getWriter();  
          
        //Getting the value from the hidden field  
        String n=request.getParameter("uname");  
        out.print("Hello "+n);  
  
        out.close();  
        }
		catch(Exception e){System.out.println(e);}  
    }  
}  

web.xml

<web-app>  
<servlet>  
<servlet-name>s1</servlet-name>  
<servlet-class>FirstServlet</servlet-class>  
</servlet>  

<servlet-mapping>  
<servlet-name>s1</servlet-name>  
<url-pattern>/servlet1</url-pattern>  
</servlet-mapping>  

<servlet>  
<servlet-name>s2</servlet-name>  
<servlet-class>SecondServlet</servlet-class>  
</servlet>  

<servlet-mapping>  
<servlet-name>s2</servlet-name>  
<url-pattern>/servlet2</url-pattern>  
</servlet-mapping>  

</web-app>  

Cookies Handling in Servlet URL Rewriting Servlet

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements