Wednesday 23 April 2014

How to create Session in jsp

             
STEP 1:   Create folder in webapps which is exising in Apache Tomcat folder
           
                Folder name as Session_example
STEP 2:   Now in Session_example folder you have to create index.html file and code as Below


               <html>

               <head>

               <title>Wel come</title>


               </head>

              <body bgcolor="#660099">



            <form name="form1" method="post" action="http://localhost:8080/Session_example             
                                                                                                 /sessionex.jsp" >

               <h1 align="center"><u>Sesssion examlpe</u></h1>
               <table width="350" align="center" style="font-family:Calibri;color:white;"  cellpadding="0" 
                cellspacing="0">
               <tr>
               <td><br>
                                Enter your name:&nbsp;&nbsp;</td>
               <td><br><input type="text" name="name" value=""> </td>
               </tr>
               <tr>
               <td><br>Enter your Surname:&nbsp;&nbsp;</td>
               <td ><br>
               <input type="text" name="sname" value=""></td>
               </tr>
               <tr>
               <td>&nbsp;</td>
               <td colspan="2"><br><input type="submit"  value="show"></td>
               </tr>
    
              </table>

              </form>

              </body>
              </html>

       
             I hope you have created it.


STEP 3: In Session_example folder create your jsp file in notepad code as below
              as per below code
           
           <% 


                String Name = request.getParameter("name");
                String sName = request.getParameter("sname");


                if (Name != null && Name.length() > 0)
                     {
                           session.setAttribute(Name, sName);
                     }
         
         
                 String value = session.getAttribute(Name).toString();
                 out.println("Your Session Name : "+Name + "<br>" +"Your Session Value : "+ value);




              %>





   STEP 4:After complation of your programm you have to open Apche server in
              browser
    
             like ,
                    http://localhost:8080/

            click on manager apps
             and then clcik on list of Application
            After that you found your example name as Session_example
           Click on Session_example link

   

Enjoy........   


Download Example

Downlod files and Extract in webapps folder

No comments:

Post a Comment

How to change Background color by selecting color from Listview

activitymain.xml file::> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     xm...