Likes

WCD-LAB @HOME 5-Ans 1

Section : Container Facilities for Servlets and JSPs (1 of 2 )


1. Investigate the deployment descriptor and the container's servlet support.



                         INVESTIGATE PROJECT USING WEB.XML
1.Create a new Java Web project named
 2.Create a Servlet .Accept thedefault name new Servlet,and place
      it in the package lab.click Next
3.Select the checkbox Add information to deployment descriptor(web.xml).
4.Modifythe URL pattern(s)field of the table labeled Initalization/*.
5.click on the New buttom to the right of thetable labeled Initialization
   parameters.types into the newly created row of the table in the values keyname
    and Data value under the headingname and Value respectively.
6.Click Finish.
7.Notice that under the project folders web pages->WEB-INF there is a new
   node namedweb.xmlDouble click on the element.
8.From the editor pane,sekect the General tab,then open the Contex Parameters
   region.(Click on the plus sign).
9.Select Add...in the Context Parameter region,enter a parameter name and a
    value.
10.Select XML at the topof the editor window,towardthe right hand end.you
     should see an XML file someWhat like this:
        1<?xml version="1.0" encoding="Utf-8"?>
         2<web-app[......]>
         3<context-param>
          4 <param-value>My parameter value</param-name>
          5 <param -value>My parametervalue</param-value>
          6 </context-param>
         7 <servlet>
         8 <servlet-name<New Servlet</Servlet-name>
       9 <servlet-
          class>s1314m5.lab.NewServlet</servlet-class>
      10 <init-param>
      11 <param-name><keyName</param-name>
      12 <param-value>Data value</param-value>
       13</init-param>
      14 </servlet>
      15 <servlet-mapping>
       16 <servlet- name>NewServlet/*</url-pattern>
       17<url-patterm>/pathToServlet/*</url-pattern>
      18 </servlet-mapping>
       19 <session-cofig>
       20 <session-timeout>
       21 30
       22 </session-timeout>
      23</session-config>
     24 </web-app>
11.Examine the XML file and determine how a triggeringURL is matched to the
      servlet class that must run in response to that URL.
12.Examine the XML file and determine how the Key-value pairs you specified
     are represented.Note also how one couple is associated specifically with the
     servlet,while-the other is at almost the top level of the XML structure andis
   outside the servlet definition.

Task -code the servlet to use the Configuration
 information
 1.Edit the sour File,Writing your code in the processRequest()method
     that has been added by NetBeans.
  2.Extract areference to the ServletContext object.
 3.Store the servlet context in a variable.
 4.Using the servlet context reference,locatedthat you think might
    provide access to a logging to a logging facility.using this method,write amessage to the
    web-container'slogging strem that indicates that the servlet has been invoked
    and output the time invocation.
5.Using the same servlet context referance,determinehow you can obtain the
    context parameter that you stored in the web.xml file.Recall from the lecture
   that this is referred to in thr APIs as an initparameter.As beforNet Beans
    typingcomplention can be used to help.
6.Output completion can be used to help.
7.Extract the value of the servlet initization parameter.Notice that this value is
    extracted directiy from the Httpservlet object(this).
8.Write the name and value of the parameter to the log stream.
9.Create a minimak HTMl page so that the servlet will generate somevisible
   output an thebrowser.Consider including the current data and time here too.

    prapare the index page and Run the Application
1.Edit the index.jsp file of the project.Create a link in it .That should jump
   to path Toserl=velt /blah.
2.run the Program.
3.Look at the GlassFish v3 Dimain tabs.one shows the buliding and
    deployement of the application.the other shows the output from
    the logging request.
4.Determine that the key/value pairs inthe logging output are correct.

WCD -LAB @HOME 4

Section : The Servlet’s Environment (1 of 1 )
1. In the ExoticaTravels Web application, a user has to make multiple selections, such as destinations, hotels, and travel tickets, to perform online booking. Therefore, you need to enable the Web application to track all these user activities across various Web pages. For this, you need to design multiple Web pages, which will allow the user to select various options, such as destination, hotel, and cab service. When the Tour Package Bookings link is clicked, the destination Web page similar to the following figure should be displayed.



<%@page contentTypes="text/html"pagedEncoding="UTF-8"%>
  <!DOCTYPE html>
    <html>
            <head>
                      <meta http-equiv="content-Types"content="text/html;
  charset=UTF-8">
                   <title>Tour page</title>
       </head>
       <body>
 
<div align="right">
                 <ahref="LogoutServlet">Logout</a>
       </div>
      <table>
     <form action='HotelBookingServlet'>
     <tr><td><h3>Tour package Booking</h3></td></tr>
   <tr><td>select a destionation</td>
          <td><selectnamee-'destionation'>
                             <option
   value='select'>Select</option>
                                     <option
value='colombo'>colombo</option>
                                     <option
value='Ella'>Ella</option>
                           <option
value='Sigiriya'>Sigiriya</option>
                             <option
value='Galle'>Galle</option>
                          <option
value='kandy'>Kandy</option>
                         </select>
              </td>
 </tr>
  <tr>
        <td><input type='sub,it'value='Next'></td>
     </tr>
  </from>
  </table>

         </body>
   </html>

import java.io.IOException;
impot\rtjava.io.PrintWriter;
impot javax.Servlet.ServletException;
import javax.Servlet.annotation.WebServlet;
import javax,Servler.http.HttpServlet;
import javax.servlet.http.HttpServleltRequest;
import javax.Servlet.http.HttpServletResponse;
import javax.Servlet.http.HttpSession;

@WebServlet(urlPatterns ={/HotelBookingServlet"})
public class HoltelBookingSrvlet extendsHttpServlet
 {
  protected void processRequest(HttpServletRequest
request .HttpServletResponse response)
      throws ServletExceptin.IOException
    {
response.setContentTYpes("text/html;cherset=UTF-8");
 printWriter out=response.getWritter();
HttpSession session=request.getSession();
  try
       {
         sysstem.out.print("1");
         String desstination=requesst.getparameter
('destionation");
                   session.setAttribute("destionattion",
 destination);
                out.println(<"title>tour packege Booking
page<title>");
out.println(<"div align=right'>");
            out.println("<a
hreff='LogoutServlet'>Logout</a>");
                 out.println("</div>");
                 out.println("<table>");
                 out.println("<form
action='cabBookingServlet'>");
                out.println("<tr><td><h3>Tour packge
Booking</h3></td></tr>");
              out.println("<tr><td>select a hotel</td>");
              out.println("<td><select name='hotel'>");
             out.println("<option
value='seclect'>Select</option>");
             out.println("<option
value='jetwing'>Jetwing</option>");
           out.println("<option
value='kells'>Kells</option>");
           out.println("<option
value='Heritance'>Heritance</option");
                 out.println("option
value='devon'>Devon</option>");
            out.println("<option
value='Hilition'>Hiliton</option></select></h1></td>");
            out.println("<tr><td>Number of days </td>");
            out.println("<td><input type='text'
name='noofdays'></td");
             out.println("<tr><td><imput types ='submit'
value='Next'></td>");
                 out.println("</form>");
                 out.println("<form
action='Tourpackage page.jsp'>");
             out.println(">td><input types='submit'
value='back'></td></tr>");
           out.println("</from>");
          out.println("<?table>");
     }
       finally
            {
               out.close();
          }
    }
@Override
   protected void goGet(HttpServletRequest request,
httpServletResponse response)
       throws ServletException.IOException
         {
     processRequest(request.response);
   }
@override
 public String getservletInfo()
      {
         return "short description";
       }
  }

 import java.io.IOException;
 import java.io.printWriter;
 import javax .servlet.ServletException;
 import javax .servlet.annotationwebServlet;
 import javax . servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.httpServletResponse;
 import javax.servlet.http.HttpSession;

@webServlet(urlPatterns ={"/cabBookingServlet"})
  public class cabBookingServlet extends HttpServlet
   
{
   protected void process Request(HttpServlet
    {
   request ,HttpServletResponse respons)
  throws servletException,IOException
     {
       response.setcontentTypes("text/thml;cherset=UTF-8");
     printWriter out = response.getWriter();
     HttpSession session = request .getSession();
     String hotel=request.getparamter("hotel");
     string noofdys=request.getparameter("noofdays");
     session.setAttribute("hotel",hotel);
     session.setAttribut("noofdays", noofdays);
     tyr
          {
            out.println("<titlr>Tour apckage Booking
  page</titel>");
                  out.println("<div alig='right'>");
                  out.println("<a
  href='LogoutServlet'>Logout</a>");
                out.println("</div>");
               out.println("<table>");
               out.println("<from
action='TourPackageServlet'>");
            out.println("<tr><td><h3>Tour package
 Booking</h3></td></tr>");
                    out.println("<tr>td>select a cab
  Service</td>");
                 out.println("<td><select name='cab'>");
                  out.println("<option
   value=select'>select</option>");
                   out.println("<option
value='Royal'>Royal</option
            out.println("<option
  value='kangaroo'>Kangaroo</option>");
            out.println("<option
 value='Derana'>Derana</option>");
         out.println("<option
value='ACE'>ACE</option>");
           out.println("<option
 value='Hilition>Hilition</option></input types='submit'
              out.println("tr><td><input type='submit'
    value='submit'></td>");
                               out.println("</from>");
                               out.println("<from
     action='HotelBookingServlet'>");
                   out.println("<td><input types='submit'
  value='Back'></td></tr>");
                     out.println("</from>");
                      out.println("</table>");
           }
    finally
                {
                       out.close();
                  }
           }
@Override
  protected void dopost(HttpServletRequest request,
HttpServletResponse response)
         throw servletException,IOException
             {
                 processRequest(request , response);
      }

@Override
  public String getServletInfo()
      {
         return"short description";
       }
 }

import java.io.Exception;
import java.io.printWriter;
import javax.servletRequesrDispatcher;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequese;
import javax.servlet/http.HttpSession;

@webservlet(urlpatterns -{/TourPaxkageServlet"})
 public class ToupackageServlet extends HttpServlet
   {

  protected void processRequest(HttpServletRequest
request ,HttpServletResponse response)
    throws ServletException,IOException
      {
         response.setContentType("text/html;charser=UTF-8");
        printWriter out =response.getWriter();
       HttpSession session=responst.getsession();
       try
               {
                      String cab=request.getparamter("cab");
                      session.setrAttribute("cab",cab);
                      RequestDispatcher
rd=request.getRequestDispatcher("DisplayServlet");
       rd.forwaed(request ,response);
        }
          finally
                   {
                          out.close();
             }
    }
   
     @Override
     protected void doGet(HttpServletRequest request,
HttpServletRespons response)
                   throws servletException,IOException
       {
              processRequest(request,response);
        }
@override
  protected void dopost(HttpServlet.Request request,
 HttpServletResponse response)
            throwsnServletEXception,IOException
           {
                  processRequest(request,response);
              }
  @override
     public StringgetServletINfo()
       {
           return"short description";
            }
      }

   import java.io.IOException;
   import java.io.printWrite;
   import javax.servlet.ServletException;
   import javax.servlet,annotation.webServlet;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
   import javax.servlet.http.HttpSession;

 @webServlet(urlpatterns ={"/DisplayServlet"})
   public class DisplayServlet extends Httpservlet
       {
         protected void processRequest(HttpServletRequest
response , HttpServletRequest response)
        throws servletException,IOException
         {
                 response.setcontentTypes("text/html;cherst=UTF-8");
         printWrite out= response.getWriter();
          HttpSession session =request.getsession();
          userDetailModel udm=
  (userDetailModel)session.getAttribut("smodel");

   try
       {
         out.print("<div align='right'>");
        out.println("<a href='LogoutServlet'>Logout</a>");
       out.println("</div>");
       out.println("<h2>Hi "+udm.getUname()+",Logout</a>");
    requested for the following booking<h2>") ;
   out.println("<h4><br>Destination:
"+session.getAttribute("destionation"));
 ouit.println("<br>Hotel:"+session.getAttribute("hotel"));
 out.println("<br>No of days:
 "+session.getAttribute("noofdays"));
       out.println("<br>cab service:
 "+session.getAttribut("cab")+</h4>");
      }
          finally
             {
              out.close();
         }
   }
  @override
    protectedvoid doget(HttpServletResquest request,
 HttpServletResponse resonse)
                 throws servletException,IOException
             {
                processRequest(reuest, response);
      }
@override
public String GetServletInfo()
{
 return "short description";
      }
  }
<%@page contenTypes="text/html"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
      <head>
                <meta http-equiv="content-types"content="text/html;
 cherset=UTF-8">
                   <title>plan Travle page</title>
       </head>
       <body>
     <div align="right">
                   <a href="LogoutServlet">Logout</a>
        </div>
         <from action="planTravel Servlet">
             <table border="0">
                  <tr>
                     <td colspan="45">
                           <h2><i>plan Travle</i><H2>
          </td>
         <td>Data of Arrival</td>
         <td>
       <select mane="arr_dd"name="arr_data">
        <option value="1">1</option>
        <option value="2">2</option>
       <option value="3">3</option>
      <option value="4">4</option>
        <option value="5">5</option>
       <option value="6">6</option>
       <option value="7">7</option>
       <option value="8">8</option>
      <option value="9">9</option>
       <option value="10">10</option>
          <option value="1"></option>
          <option value="11">11</option>
          <option value="12">12</option>
         <option value="13">13</option>
          <option value="14">14/option>
          <option value="15">15</option>
          <option value="16">16</option>
            <option value="17">17</option>
        <option value="18">18</option>
            <option value="19">19</option>
              <option value="20">20</option>

               <option value="21">21</option>    
              <option value="22">22</option>
                  <option value="23">23</option>
                   <option value="24">24</option>
                   <option value="25">25</option>
                      <option value="26">26</option>
                      <option value="27">27</option>
                       <option value="28">28</option>
                       <option value="29">29</option>
                        <option value="30">30</option>
                        <option value="31">31</option>
    </slect>
_
<select name="arr_mm">
                <option value="jan ">january</option>                
                  <option value=" feb">february</option>              
                  <option value="mar ">march</option>              
                   <option value=" Apr">April</option>              
                    <option value="May ">May</option>              
                    <option value="Jun ">june</option>
                    <option value="jul ">july</option>              
                    <option value="Aug ">August</option>              
                   <option value="Sep ">September</option>              
                    <option value=" oct">october</option>              
                     <option value="nov ">november</option>
                     <option value="Dec ">December</option>
     </select>
     _
        <select name="arr_yy">
         <option value="2013">2013</option>
          <option value=" 2014">2014</option>              
         <option value=" 2015">2015</option>              
         <option value="2016 ">2016</option>              
         <option value="2017 ">2017</option>              
          <option value=" 2018">2018</option>              
          <option value="2019 ">2019</option>              
          <option value=" 2020">2010</option>                                                      
    </select>
    </td>
    <tr>
            <td>Data of Departure</td>
           <td>
                <selct name="dep_dd">
             <option value="1">1</option>
              <option value="2 ">2</option>              
              <option value=" 3">3</option>              
              <option value="4 ">4</option>              
               <option value="5 ">5</option>              
               <option value="6 ">6</option>
                <option value=" 7">7</option>              
                 <option value=" 8">8</option>              
                  <option value="9 ">9</option>              
                  <option value=" 10">10</option>              
                     <option value="11 ">11</option>              
                  <option value=" 12">12</option>              
                <option value="13 ">13</option>              
               <option value=" 14">14</option>              
                <option value=" 15">15</option>              
                 <option value=" 16">16</option>              
                   <option value="17 ">17</option>              
                  <option value="18 ">18</option>              
                  <option value=" 19">19</option>              
                 <option value=" 20">20</option>              
               <option value="21 ">21</option>              
                 <option value="22 ">22</option>              
               <option value="23 ">23</option>              
           <option value=" 24">24</option>
              <option value=" 25">25</option>              
                <option value="26 ">26</option>              
               <option value="27 ">27</option>
                <option value=" 28">28</option>              
                 <option value="29 ">29</option>              
                 <option value="30 ">30</option>
                    <option value=" 31">31</option>                                                                                  
   </select>
    _
   <select name="dep_mm">
                      <option value=" jan">january</option>              
                      <option value="Fed ">february</option>              
                         <option value="Mar">March</option>              
                       <option value=" Apr">April</option>              
                           <option value=" May">May</option>              
                           <option value="jun ">june</option>              
                        <option value=" jul">july</option>              
                      <option value=" Aug">August</option>              
                       <option value="Sep ">September</option>              
                         <option value="oct ">october</option>              
                           <option value="Nov ">Nov</option>
           
                         <option value=" Dec">December</option>              
                                     
          </select>
            _
                    <select name="dep_yy">          
                           <option value="2013 ">2013</option>              
                            <option value="2014 ">2014</option>              
                            <option value="2015 ">2015</option>              
                           <option value=" 2016">2016</option>              
                              <option value="2017 ">2017</option>              
                           <option value="2018 ">2018</option>              
                              <option value="2019 ">2019</option>              
                          <option value="2020 ">2010</option>  
     </select>
        </td>
         </tr>
        </table>
                <tr>
              <td colspan="2">what kind of Holiday do you
  prefer?</td>
                </tr>
                   <td><imput name="Kind_wild"types="checkbok"
 value="wild and Adventurous"/>
                wil &amp;Adventurous</td>
             <td><input name="Kind_romatic" types="check"
      value="Romantic andSensuous/>
               Romantic &amp;Sensuous</td>
        </tr>
        <tr>
                  <td><input name=Kind_fun"types="checkbok"
          value="fun and Exciting"/>
         Fun & amp; Exciting</td>
   <td><input name="Kind peaceful"types="checkbok"      
value="Thought provoking and peaceful"/>
                   Thought provoking &amp;
   peaceful</td>
                   </tr>
                     <tr>
                    <td><imput name="Kind_healthy" type="checkbox"
value="Healty and rejuvenating"/>
                      Healthy &amp;rejuvenating</td>
                    <td>&nbsp;</td>
                    </tr>
                      <tr>
                        <td>&nbsp;</td>
                         <td>&nbsp;</rd>
                           </tr>
                             <tr>
                            <td colspan="2">what would you like to see in a
holiday?</td>
               </tr>
                  <tr>
                 <td><input name="like_beaches"type="checkbok"
value="Beaches"/>
               Beaches</td>
                 <td><input name="like_archaeological"
 types="checkbook"value="Archaeological sites"/>
              Archaeological sites</td>
                    </tr>
                    <tr>
                  <td><input name="like_mountains"
types="checkbox" value="Mountains and waterfalls"/>
                   Mountains &amp; waterfalls</td>
                 <td><input name="like_widlife"type="checkbox"
value="wild Life"/>
              Wild Life</td>
            </tr>
           <tr>
            <td><input name="like_fauna"types="cheackbok"
value="wild Life"/>
                    wild Life</td>
              </tr>
              <tr>
                   <td><input name="like_fauna" type="checkbok"
  value="Fauna and flora"/>
  Fauna &amp; flora</td>
                    <td>&nbsp;</td>
                          </tr>
                              <tr>
                                 <td>&nbsp;</td>
                                  <td>&nbsp;</td>
                       </tr>
                       <tr>
                         <td colspan="2">what is the most important
facility you need?</td>
                  </tr>
                  <tr>
                       <td><input name="faci_accomodation"
 types="checkbox" value="comfortable accommodation"/>
                        comfortable accommodation </td>
                           <td><input name="faci_food+type="checkbok"
value="Excellent food"/>
Excellent food </td>
               </tr>
                <tr>
                  <td><input name="faci_transport"
type="checkbox" value="Transportation"/>
 Transportation</td>
                   <td><input name="faci_comm" type="checkbox"
value="Communication"/>
Communication</td>
                     </tr>
                      <tr>
                       >td><input name="faci_guide" types="checkbox"
value="Guide assistance"/>
Guide assistance</td>
                  <td>&nbsp;</td>
                  </tr>
                   <tr>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                     </tr>
                        <tr>
                                  <td colspan="2">what kind of accommodation
pleases you?</td>
                      </tr>
                          <tr>
                          <td><input name="budget"types="checkbox"
value="budget Guest Houses"/>
                       Budget Guest Houses</td>
                       <td><input name="standard" type="checkbox"
 value="Standard Hotels"/>
 standard Hotels</td>
                   </tr>
                   <tr>
                     <td><input name="start2_3"type="checkbox"
value="2-3 Start Hotels"/>
2-3 Start Hotels</td>
               <td><input name="start4_5"type="checkbox"
value="4-5 star Hotels"/>
                   4-5 Start Hotels</td>
                    </tr>
                     <tr>
                             <td>&nbsp;</td>
                       </tr>
                     </table>
                   <table border="0">
                        <tr>
                          <tr><td><input type="submit"
value="Submit"/></td></tr>
                    </table>
           <body>
  </html>

import java .io.BufferedWriter;
import java .io.FileWriter;
import java .io.IOException;
import java .io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServlet.Request;
import javax.servlet.http.HttpServlet.Response;
import javax.servlet.http.HttpSession;

@WebServlet(name ="planTravelServlet", urlpatterns =
{"/planTravelServet"})
public class planTravelServlet extends HttpServlet
  {
    UserDetailsModel udm=new userDetailsModel( );
     String
arr_dd,arr_mm,arr_yy,arrDate,dep_dep_mm,dep_yy,depDate;
  string
Kind_wild.kind_romantic.Kind_fun,Kind_peaceful,kind_healthy
,holidayskind ;
   String
 like_beaches,like_archaeological.like_mountains,like_wildli
fe,like_fauna.holidayLike;
  string
like_beacuse.like_arachaeological,like_mounatins,like_wildli
fe,like_fauna, holidayLike;
    string
faci_accomodation,faci_food,faci_transport.faci_comm.faci_g
uide,facilities;
  String budget,standard,start2_3,start4_5,accomodation;
  FileWriter fw;
  BufferWriter bw;
  HttpSession session;
  protected voidprocessRequest(HttpServletrequest
request ,httpServletResponse reponse)
                throws ServletEXceptiopn ,IOException
                  {
repons .setcontentType("text/html;cherset=UTF-8");
 printWriter out =response.getWriter();
 session=request.getsession();
  try
    {
      System.out.println("1_1");
      udm=(UserDetailsModel)session.getAttribute
 ("smodel");
                  system.out.Println(udm);
                 arr_dd_request.getparameter("arr_dd");
                    arr_mm=request.getparameter("arr_mm");
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
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.HttpServletReponse;
import javax.servlet.http.HttpSession;

@WebServlet(name ="planTravle Servlet", urlpatterns =
{"/planTravelServlet"})
public class planTravelServlet extends HttpServlet
  {
    UserDetailsModel udm=new userDetailsModel( );
     String
arr_dd,arr_mm,arr_yy,arrDate,dep_dep_mm,dep_yy,depDate;
  string
Kind_wild.kind_romantic.Kind_fun,Kind_peaceful,kind_healthy
,holidayskind ;
   String                      
like_beaches,like_archaeological.like_mountains,like_wildli
fe,like_fauna.holidayLike;
  string
like_beacuse.like_arachaeological,like_mounatins,like_wildli
fe,like_fauna, holidayLike;
    string
 faci_accomodation,faci_food,faci_transport.faci_comm.faci_g
uide,facilities;
  String budget,standard,start2_3,start4_5,accomodation;
  FileWriter fw;
  BufferWriter bw;
  HttpSession session;
  protected voidprocessRequest(HttpServletrequest
request ,httpServletResponse reponse)
                throws ServletEXceptiopn ,IOException
   respons .setcontentType("text/html;cherset=UTF-8");
 printWriter out =response.getWriter();
 session=request.getsession();
  try
    {
      System.out.println("1_1");
      udm=(UserDetailsModel)session.getAttribute
 ("smodel");
                  system.out.Println(udm);
                 arr_dd_request.getparameter("arr_dd");
                    arr_mm=request.getparameter("arr_mm");              
                                         
                 arr_yy=request.getparameter("arr_dd");
                  arrData=arr_dd+"."+arr_mm+"."+arr-yy");
                   dep_dd=request.getparameter("dep_dd");
                  epons .setcontentType("text/html;cherset=UTF-8");
 printWriter out =response.getWriter();
 session=request.getsession();
  try
    {
      System.out.println("1_1");
      udm=(UserDetailsModel)session.getAttribute
 ("smodel");
                  system.out.Println(udm);
                 arr_dd_request.getparameter("arr_dd");
                    arr_mm=request.getparameter("arr_mm");
                                                 
                 epons .setcontentType("text/html;cherset=UTF-8");
 printWriter out =response.getWriter();
 session=request.getsession();
  try
    {
      System.out.println("1_1");
      udm=(UserDetailsModel)session.getAttribute
 ("smodel");
                  system.out.Println(udm);
                 arr_dd_request.getparameter("arr_dd");
                    arr_mm=request.getparameter("arr_mm");
                   
               arr_yy=request.getparameter("arr_yy");
               arrData="arr_dd+"."+arr_mm+"."+arr_yy;
              dep_dd=request.getparameter("dep_dd");
               dep_mm=request.getparameter("dep_dd");
               dep_yy=ruquest.getparameter("(dep_yy");
               depData=dep_dd+"."+dep_mm+"."+dep_yy;
                kind_wild=request.getparameter("Kind_wild");
                 kind_remantic=request.getparameter
("kind_romantic");
                  kind_fun=request.getparameter("kind_fun");
                  kind_peaceful=request.getparameter
("king_peaceful");
                      kind_healthy=request.getparameter
("kind_healthy");
                if(kind_wild!null)
                 holidayKind=kind_romantic+",";
                 if(kind_romantic!=null
                   holidaykind+=kind_romantic+"," ;
             if(kind_fun!=null)
                   holidaykind+kind=kind_fun+"," ;
               if(kind_peaceful!=null)
                            holiykind+=kind_peaceful+"," ;
               if(kind_healthy!=null)
                                    holidaykind+=healthy+" ," ;
               like_beaches=request.getparameter
   ("like_beaches");
                   like_archaeological=request.getparameter
  ("like_archaeological");
                       like_mountains=request.getparameter
  ("like_mountains");
                              like_wildlife=request.getparameter
  ("like_wildlife");
                   like_faune=request.getparameter("like_fauna");

     if (like_beaches!=null)
             holidayLike+like_beaches+"," ;
     if(like_archaeologival !=null)
               holidayLike+=like_archaeological+"," ;
           if(like_monuntatins !=null)
             holidayLike+=like_mountains+" ," ;
      if(like_wildlife!=null)
            holidayLike+=like_wildlife+" ," ;
    if(like_archaeological!=null)
          holidayLike+=like_fauna+" ," ;

                 faci_accomodation=request.getparameter
("faci_accomodation");
                        faci_food=request.getparametar
("faci_accomodation");
                  faci_transport=request.getparameter
 ("faci_accmodation");
                  faci_comm=request.getparameter
("faci_accomodation");
                 faci_guide=request.getparameter
("faci_accomodation");
                         if(faci_accomodation!null)
                          facilities=faci_accomodation+",";
                           if(faci_food!=null)
                            facilities+=faci_food+" , " ;
                           if(faci_transport!=null)
                           facilitices+=faci_transport+", " ;
                           if(faci_comm!=null)
                             if(faci_guide!=null)
                           facilities+=faci_guide+" ," ;

                 budget=request.getparameter("budget");
                 standerd=request.getparameter("standard");
                start2_3=request.getparameter("start4_5");
               start4_5=request.getparameter("star4_5");
                 if(budget!=null)
                         accomodation=buget+" ,";
       if(standard!=null)
                 accomodation+=standard+" ," ;
      if(start2_3!=nuu)
             accomodation+=star2_3+"," ;
      if(start4_5!null)
            accomodation+=start4_5+" ," ;

         system.out.println(udm.getUname
()+" ,"+getAddress()+"~"+holidayLike+"~"facilites
+"~"+accomodation);
              writeData();
               RequestDispatcher
rd=request.getRequestDispatcher("DisplayTravelplan.jsp");
                rd.forword(request ,response);
     }
       finally
                 {
             }
      }

public void writeData()
     {
    try
         {
              System.out.orintln("1");
             fw=new FileWriter("planTravel/txt" ,true);
              bw=new BufferedWriter(fw);
              bw.Write (udm.getUname()+"~"+depdate
 ()+"~"+udm.getcontactno()+"~"+arrData+"~"+depDate
+"~"+holidayKind+"~"+holidayLike+"~"facilities
+"~"+accomodation);
       bw.newLine();
       system/out.println("2");
       bw.close();
      fw.close();
       }
       catch (Exception e)
          {
               system.out.println(e);
                  }
            }
   @override
    protected void goGet(HttpServletRequest request,
HttpServletResponse respose)
                  throw ServletException, IOException
        {
              processRequesr(requesr ,response);
                   }
 
  @override
    protected void goGet(HttpServletRequest request,
HttpServletResponse respose)
                  throw ServletException, IOException
        {
              processRequesr(requesr ,response);
                   }
   @override
   public String getServletInfo()
      {
         return"short description";
       }
}
<%@page contentType="text/html" pageEncoding="UTF-8"%>
 <!DOCTYPE html>
 <html>
            <head>
                     <meta http-equiv="Content-TYpe"content="text/html;
charset=UTF-8">
            <title>Display Travel plan page</title>
      </head>
      <body>
                  <div align="right">
                              <a href="LogoutServelt">Logout</a>
             </div>
              <h1>Thank you.Our customer care executive will
contact you soon </h1>
        </body>
   </html>

<div align="right">
                  <a href="LogoutServlet">Logout</a>
    </div>

<td><a href='TourPackagePage.jpg'><img
   src="Image/Tourpackage .jpg"height="150"width="250"></a>
<td><a href='planTravelpage.jsg'><img src="Images/planTour.jpg"
height="150"planTravelpage.jsp'><img src="Images/planTour.jpg

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
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.HttpServletReponse;
import javax.servlet.http.HttpSession;

@WebServlet(name ="LogoutServlet",urlpatterns=
 {"/LogoutServlet"})
  public class LogoutServlet extends HttpServlet
        {
     HttpSession session;
      protected void processRequest(HttpServletRequest
request , HttpServletResponse response)
                 throws ServletException, IOException
            {
  response . setContentType("text/html;charset=UTF-8");
  printWriter out = response.getWriter();
   try
        {
          session=request.getSession();
          session.invalidate();
          Requestispatcher
rd=request.getRequestDispatcher("MainPage.jsp");
       rd.forword(request ,response);
       }
          finally
                     {
                          out.close();
                }
    }

@Override
   protected void doGet(HttpServletRequest request,
HttpServletResponse response)
                    throws ServletException,IOException
             {
       processRequest(request , response);
       }
                   
@override
    protected void doPost(HttpServletRequest request,
HttpServletResponse respose)
                  throw ServletException, IOException
        {
              processRequesr(requesr ,response);
                   }
@override
    protected void doPost(HttpServletRequest request,
HttpServletResponse respose)
                  throw ServletException, IOException
        {
              processRequesr(requesr ,response);
                   }

   @override
   public String getServletInfo()
      {
         return"short description";
       }
}

                   
                             
                                         


           

 
 
   
           





           





       

     


 

             








WCD -LAB @HOME 3


1. Enhance the ExoticaTravels Web application by implementing the following functionalities using the MVC architecture:
When the user clicks the submit button of the registration page, the details entered in the registration page should be stored in a file and the welcome page should be displayed similar to the following figure.
The welcome page should have hyperlinks for cab bookings, hotel bookings, tour package bookings, and plan travel.When the user submits the login page, the login credentials should be validated. If the credentials are valid then the welcome page should be displayed, else an error page should be displayed.Note: To perform this exercise, you need to use the solution created in Exercise 01 of Chapter 02. In addition, you need to use the Car.jpg, PlanTour.jpg, Hotel.jpg, and Tourpackage.jpg images.                          
          


To solve this exercise, you reed to perform the following steps:
1. Open the Web application. ExoticaTravels.
2. Create a Java class. UserDetailsModel.java. and replace the existing cede with the following cede:
public class UserDetailsModel {
String uname, address, contactno, loginid, password;
public UserDetailsModel(){
public UserDetailsModel(String uname, String address. String contactno. String loginid. String password) { this.uname = uname; this.address = address; this.contactno = contactno; this.loginid = loginid; this.password = password;
}
public String getUname() { return uname;
}
public String getAddress() { return address;
}
public String getContactno() { return contactno;
}
public String getLoginid() { return loginid;
}
}
public String getPassword() { return password;
}
public void setUnaxne (String uname) { this . uname = uname;
)
public void setAddress(String address) { this.address = address;
>
public void setContactno(String contactno) { this.contactno = contactno;
}
public void setLoginid(String loginid) { this.loginid = loginid;
}
public void setPassword(String password) { this.password = password;
}
3. Create a servlet. LoginServlet.java. and replace the existing code with the following code:
import
import
import
import
import
import
import
import
import
import
java.io.BufferedReader ;
java.io.FileReader;
j ava.io.IOException;
java.io.PrintWriter;
javax.servlet.RequestDispatcher;
javax.servlet.ServletException;
javax.servlet.annotation.WebServlet;
j avax.servlet.http.HttpServlet;
javax.servlet.http.HttpServletRequest;
javax.servlet.http.HttpServletResponse;
@WebServlet(urlPatterns = {"/LoginServlet"}) public class LoginServlet extends HttpServlet {
String loginld, password,uname;
UserDetailsModel udm=new UserDetailsModel(); protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8")
PrintWriter out = response.getWriter();
try {
loginId=request.getParameter("loginid"); password=request.getParameter("password");
boolean value=readFile();
if(value){
request.setAttribute("model", udm); RequestDispatcher
rd=request.getRequestDispatcher("WelcomePage.jsp");
rd.forward(request, response)
}
else {
RequestDispatcher
rd=request.getRequestDispatcher("ErrorPage.j sp");
rd.forward(request, response);
>
} finally {
out.close();
>
}
boolean readFile(){
boolean value=£alse; try{
FileReader fr=new FileReader ("ExoticaTravelLogin.txt"); BufferedReader br=new BufferedReader(fr);
String data;
while((data=br.readLine())!=null){
String text()=data.split ("-");
if(text[3].equals(loginld)&& text(4).equals
(password))
{
uname=text(0) ;
udm.setUname(uname);
value=true;
break;
)
else {
value=false;
}
else{
value=false;
}
}
fr.close();
}catch(lOException ioe){
System.out.println(ioe);
}
return value;
}
©Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, lOException { processRequest(request, response);
}
©Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, lOException { processRequest(request, response);
}
©Override
public String getServletlnfo() { return "Short description";
} }
4. Create a servlet. RegistrationServlet.java. and replace the existing cede with the following cede:
import
import
import
import
import
import
import
import
import
import
java.io.BufferedWriter;
java.io.FileWriter;
java.io.IOException;
java.io.PrintWriter;
javax.servlet.RequestDispatcher;
javax.servlet.ServletException;
j avax.servlet.annotation.WebServlet;
javax.servlet.http.HttpServlet;
javax.servlet.http.HttpServletRequest;
javax.servlet.http.HttpServletResponse;
@WebServlet(urlPatterns = {"/RegistrationServlet"}) public class RegistrationServlet extends HttpServlet { String uname, city, contactno, loginid, password;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try {
uname=request.getParameter ("uname") ; city=request.getParameter("city"); contactno=request.getParameter("contactno"); loginid=request.getParameter("loginid"); password=request.getParameter("password"); writeFile () ;
UserDetailsModel udm=new UserDetailsModel (uname,city,contactno,loginid,password);
request.setAttribute("model", udm);
RequestDispatcher
rd=request.getRequestDispatcher("WelcomePage.j sp"); rd.forward(request,response);
) finally {
out.close();
    }
  }
void writeFile(){ try{
FileWriter fw=new FileWriter ("ExoticaTravelLogin.txt",true);
BufferedWriter bw=new BufferedWriter(fw) bw.write (uname+"-"+city+"-"+contactno +"-"+loginid+"^"+password);
bw.newLine(); bw.close(); fw.close();
}catch(IOException ioe){
System.out.println(ioe);
}
}
0Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { processRequest(request, response);
}
@Override
public String getServletlnfo() { return "Short description";
}
5. Add the Car.jpg Hotel.jpg. Tourpackage.jpg and PlanTour.jpg images to the Images fokSer.
6. Create a JSP page. WelcomePage.jsp, and replace the existing code with the following code:
<%8page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html charset=UTF-8">
<title>Welcome Page</title>
</head>
<body>
<hl>Welcome ${model.uname}</hl>
<table border="0" align="center">
<tr>
<td><a
href =' PageUnderConstruction. j sp' Xiang src="Images/Car .jpg" height="150" width="250"x/a></td>
<tdxa
href='PageUnderConstruction.j sp'><img
src="Images/Hotel.jpg" height="lSO" width="2S0"X/aX/td> <td><a
href='PageUnderConstruction.j sp'Xing
src="Images/Tourpackage.jpg" height="150" width="250"X/a> <tdXa
href =' PageUnderConstruction. j sp' Ximg
src="Images/PlanTour. jpg" height="150" width="250"X/a> </tr>
<tr>
<td align="center">Cab Bookings</td>
<td align="center">Hotel Bookings</td>
<td align="center">Tour Package
Bookings</td>
<td align="center">Plan Travel</td>
</tr>
</body>
</htral>
7. Create a JSP page. ErrorPage.jsp. and replace the existing code with the following code:
<%8page contcntType="text/htral" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Error Page</title>
</head>
<body>
<hl>Invalid login</hl>
</body>
</htral>
8. Open the LoginPage.jsp file and replace the statement. <for=>. with the statement. <for= sc?ior.=-L&jir.Ser-.-ier">.
9. Open the RegistrationPage.jsp file and replace the statement.<£or=>. with the statement. <£or= sc^ior.="?.egi:rrsrior.£ervle^">.
10. Run the HomePage.jsp file.

WCD-LAB @HOME 1-Ans 3

Section : Introduction to Java Server Pages (1 of 1)1. Create an HTML form and a simple JSP that handles input from that form.



the servlet system described in the previous modules provides asimple
and effective way to use java to respond to HTTP request.when combined
with the powerful and varied library APIS available to a java program,
HTmL page that implement the designs are frequently created using"
what you see is what you get"(WYSIWYG)Graphical user interface(GUI)based design tools.
such design tools works on HTML,not HTMLembedded in java programe code.

because of thethis,pure servlet approach beacomes unmanageable-often catastrophically-
when maintenance is required on the web page.having to re-types all the HTML code back
into out.print(.....)statements would be a very time consuming and error prone process.

while a servlet isajava source file containing embeddedd HTML,A JSP might be consigered to be an HTML file
with java embedded in it,code2-1below shows  an example of the very simple jsp.

1.<%--
2 simple hello world jsp example
3---%>
4
5<%@page content type="text/html"pageEncoding="UTF-8"%>
6!DOCTYPE HTML PBLIC"-//W3c//DTD HTML4.01 transitional//EN"
7"HTTP://www.w3.org/TR/html4/losse.dtd">
8
9<html>
10 <head>
11<meta http-equive="content-type" content="text/html;charset=UTF-8">
12<title>JSP page</title>
13</head>
14<body>
15<h1><%="HELLO world ! I'm a jsp,it is"+new java.util.data()%></h1>
16</body>
17</html>

          Reding inputparameters from the browser
when a brower submits a from,the request commonly parameter,that is,data
provided by the user.these parameter re avilable to a servlet througth the get parameter
method of the request variable,AS you have just seen,this means that a jsp also has
access to the same adata .prameters from are supplied in name/value pairs,and the
get parameter method takes that name as a lookup key,ND returns the associated value.

*the bulk of the documrnt is a regular HTML file;indeed ,it is entirely legal
 HTML.and can be editedin a WYSIWYG editor.
*Additional features related to the java aspects of the JSP are dented using the
<%........%>
*within<%......%>paies,three distinct variations are exemplified.these are:
      . comments(line1through3)
      . A"page directive"(line5)
      .an"expression"(line15)
the expression is computed using java and the resulit is converted toa string.that string is
then embedded into the onto HTML page to be partof the ouput that is sent to that browser.

WCD -LAB @HOME 1-Ans 2

Section : Introduction to Java Servlets ( 2 of 2 )2. Create a Web application that displays the message, Welcome to Java Servlets, when executed, as shown in the following figure.



                                      java servlets
*A java servlet is similar to a CGI program,which responds to HTTP requst and scr runs
 on the web server.
* The servlet runs as a thresd in the web container instead of a separate os process.
*THe web conainer itself is os process.but it runs s a service and is avilavble continuausly
  in contrastto the CGIscript,which creates new prcess for each request .
*when the number of rquests for a servlet rises,on additional instances of the servlet or as
  process are created.
*Each request is process concurrently using one java thread per rquest.
   
                       INTRODUCING A WEB CONTAINER
*A web container is a runtime enviroment that manages the components,such as servlets,
 java server pages(JSP)page,filtes,web event listenersof theweb application.
*the following features are provided by the web container to all web application:-
  (1)communciton support
(2)life cyclemanagement
(3)Multithreading support
(4)declarative securty
(5)JSPSupport

                        ADVANCTAGE AND DISADVANtge of java servlets
*The advantageof servlest are:-
(1)servletrequest processing is faster thanCGIprocessing because each request
  is run in a separate thread within a single process.
(2)servlet are more scalable thanCGI because more requests can be executed because the
   web cantainer user a thread rther than n os process.
(3)servlet benefit from the simple,robust,paltfrome-independent and object-
oriented nature of the jv programming language.
(4)servlets hava access to standardize and easy-to-use logging capablities.
(5)the webcontainer provides additional services to the servlets,such handling and security.
   
                           the disavantage of servlets
*servlets can only be written in the java programming languge,so developers are requesr to be
  competentwith this language.
*servlets might introduce new cancurrency issues not found in CGI.

WCD -LAB @HOME 1-Ans 1

1. Create a simple servlet.


Note: The detailed steps to perform the exercise are given in the courseware.


import java.io.IoException;

@Webservlet(urlpatterns={"/Firstservlet"})
public classFirstservlet exends extends HttpServlet"})

protected void processRequest (Httpservlet Request request,
HttpServletRespons response)

              throws servletException,IOException {
 response.setcontentType("text/html;charset=UTF-8");
printwriter out =response.getwriter();

try {

  out.println("<!DOCTYPE html>");
  out.println("<html>");
 out.println("<head>");
 out.pritnln("<title>servlet Firstservlet</title>");
 out.println("</head>");
 out.println("<body>");
 out.println("<h1>welcome to java servlets</h1>");

   out.println("</body>");
   out.println("</html>");
  } finally {
    out.close();
      }
 }
@override
protected void doGet(HttpservletRequest request,
HttpServletResponse response)
      throws servletException ,ioException {
processRequest(request, respose);
}

@Override
protected void dopost(HttpservletRequest request,
HttpServletResponse response)
              throw servletException,IOException {
    processRequest(request,response);
 }

@override
public string getservletInfo() {
return"short description";
   }
}

Core java Ans 3 Assignment

import java.sql.*;
import java.util.*;
class JoinTable
{
public static void main(String[] args) throws SQLException
{
try
{
Class.forName("sun.jdbc.odbc.jdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:Sql","sa","password@123");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select Booking_id , Customer_Name, RoomCatagory_id,Room_id, Checkin_Date, Checkout_Date, Tariff");
while (rs.next())
{
System.outlprintln("\n"+rs.getInt(1)+"\t"+rs.getInt(2)+"\t"+rs.getString(3)+"\t"+rs.getString(4)+
"\t"+rs.getString(5)+"\t"+rs.getString(6)+"\t"+rs.getString(7)+"\t"+rs.getInt(8)+);
}
con.close();
stmt.close();
}
catch(Exception e)
{
}
System.out.println("Records retreived successfully....");
}
}