my if condition is not working


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: my if condition is not working

  1. #1
    satish Guest

    my if condition is not working




    Hi,

    Please check with the code below, I am trying an example pgm where is it
    prints all the credit card details entered by the user on to screen, but
    then I retriving the credit card type value from the GUI-html selectbox using
    req.getParameter("cardtype); and then trying to print it useing if stmt,,,but
    it is not working..pls emamine the code below and solve my problem

    satish





    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import java.io.*;



    public class paymentservlet extends HttpServlet
    {




    public void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    {



    res.setContentType("text/html");

    PrintWriter out = res.getWriter();




    HttpSession session = req.getSession(false);


    String cno = req.getParameter("cardno");




    if(cno != null)

    { session.putValue("card.no", cno) ;

    out.println("The Card No is " + cno) ; }



    else

    { out.println("The Card No cannot be empty") ;
    }




    String ctype = req.getParameter("cardtype");



    if(ctype == "VISA")
    {
    out.println("you are paying by " + ctype ) ;

    }
    else if(ctype == "MASTER")
    {
    out.println("you are paying by " + ctype ) ;

    }
    else if(ctype == "DELTA")
    {
    out.println("you are paying by " + ctype ) ;

    }
    else if(ctype == "SWITCH")
    {
    out.println("you are paying by " + ctype ) ;
    }

    String sdt = req.getParameter("startdat");

    out.println("your cards Starting date is " +
    sdt ) ;


    String edt = req.getParameter("expdat");

    out.println("your cards Expiry date is " + edt
    ) ;

    }



    }









  2. #2
    Nikhil Guest

    Re: my if condition is not working


    Satish,
    Can you please clear the followings?
    1) what is the select box for card type? Radio Button Or Check BOx or List(
    select option..)? If it is List Box ( I mean <select> <option> .. ) then
    tell me whether user can select Multiple or single..

    2)is the following if not working?
    if(ctype == "VISA")

    Cheers,
    Nikhil

    "satish" <satish_141@yahoo.com> wrote:
    >
    >
    >
    >Hi,
    >
    > Please check with the code below, I am trying an example pgm where is it
    >prints all the credit card details entered by the user on to screen, but
    >then I retriving the credit card type value from the GUI-html selectbox

    using
    >req.getParameter("cardtype); and then trying to print it useing if stmt,,,but
    >it is not working..pls emamine the code below and solve my problem
    >
    >satish
    >
    >
    >
    >
    >
    >import javax.servlet.*;
    >import javax.servlet.http.*;
    >import java.sql.*;
    >import java.io.*;
    >
    >
    >
    >public class paymentservlet extends HttpServlet
    >{
    >
    >
    >
    >
    > public void doPost(HttpServletRequest req, HttpServletResponse res)
    >throws ServletException, IOException
    > {
    >
    >
    >
    > res.setContentType("text/html");
    >
    > PrintWriter out = res.getWriter();
    >
    >
    >
    >
    > HttpSession session = req.getSession(false);
    >
    >
    > String cno = req.getParameter("cardno");
    >
    >
    >
    >
    > if(cno != null)
    >
    > { session.putValue("card.no", cno) ;
    >
    > out.println("The Card No is " + cno) ; }
    >
    >
    >
    > else
    >
    > { out.println("The Card No cannot be empty") ;
    >}
    >
    >
    >
    >
    > String ctype = req.getParameter("cardtype");
    >
    >
    >
    > if(ctype == "VISA")
    > {
    > out.println("you are paying by " + ctype )

    ;
    >
    > }
    > else if(ctype == "MASTER")
    > {
    > out.println("you are paying by " + ctype ) ;
    >
    > }
    > else if(ctype == "DELTA")
    > {
    > out.println("you are paying by " + ctype ) ;
    >
    > }
    > else if(ctype == "SWITCH")
    > {
    > out.println("you are paying by " + ctype ) ;
    > }
    >
    > String sdt = req.getParameter("startdat");
    >
    > out.println("your cards Starting date is " +
    >sdt ) ;
    >
    >
    > String edt = req.getParameter("expdat");
    >
    > out.println("your cards Expiry date is " + edt
    >) ;
    >
    > }
    >
    >
    >
    >}
    >
    >
    >
    >
    >
    >
    >
    >



  3. #3
    Badri Guest

    Re: my if condition is not working


    you cannot use "==" for comparing String, instead u should use ".equals("XXX")"
    method for example,

    instead of.
    if(ctype == "VISA")

    do this
    if(ctype.equals("VISA")....

    This should work for you.

    --Badri.



  4. #4
    Aponte Guest

    Re: my if condition is not working


    "satish" <satish_141@yahoo.com> wrote:
    >
    >
    >
    >Hi,
    >
    > Please check with the code below, I am trying an example pgm where is it
    >prints all the credit card details entered by the user on to screen, but
    >then I retriving the credit card type value from the GUI-html selectbox

    using
    >req.getParameter("cardtype); and then trying to print it useing if stmt,,,but
    >it is not working..pls emamine the code below and solve my problem
    >
    >satish
    >
    >
    >
    >
    >
    >import javax.servlet.*;
    >import javax.servlet.http.*;
    >import java.sql.*;
    >import java.io.*;
    >
    >
    >
    >public class paymentservlet extends HttpServlet
    >{
    >
    >
    >
    >
    > public void doPost(HttpServletRequest req, HttpServletResponse res)
    >throws ServletException, IOException
    > {
    >
    >
    >
    > res.setContentType("text/html");
    >
    > PrintWriter out = res.getWriter();
    >
    >
    >
    >
    > HttpSession session = req.getSession(false);
    >
    >
    > String cno = req.getParameter("cardno");
    >
    >
    >
    >
    > if(cno != null)
    >
    > { session.putValue("card.no", cno) ;
    >
    > out.println("The Card No is " + cno) ; }
    >
    >
    >
    > else
    >
    > { out.println("The Card No cannot be empty") ;
    >}
    >
    >
    >
    >
    > String ctype = req.getParameter("cardtype");
    >
    >
    >
    > if(ctype == "VISA")
    > {
    > out.println("you are paying by " + ctype )

    ;
    >
    > }
    > else if(ctype == "MASTER")
    > {
    > out.println("you are paying by " + ctype ) ;
    >
    > }
    > else if(ctype == "DELTA")
    > {
    > out.println("you are paying by " + ctype ) ;
    >
    > }
    > else if(ctype == "SWITCH")
    > {
    > out.println("you are paying by " + ctype ) ;
    > }
    >
    > String sdt = req.getParameter("startdat");
    >
    > out.println("your cards Starting date is " +
    >sdt ) ;
    >
    >
    > String edt = req.getParameter("expdat");
    >
    > out.println("your cards Expiry date is " + edt
    >) ;
    >
    > }
    >
    >
    >
    >}
    >
    >
    > Probably you need to convert the info to UpperCase.


    String ctype = ctype.ToUpperCase();

    If not, check the parameter name and make sure is "cardtype".

    >
    >
    >
    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center