-
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
) ;
}
}
-
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
>) ;
>
> }
>
>
>
>}
>
>
>
>
>
>
>
>
-
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.
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks