cannot find mymbol method parseDate(java.lang.String)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • creative1
    Contributor
    • Sep 2007
    • 274

    cannot find mymbol method parseDate(java.lang.String)

    hi,
    I am new at writing JSP and Servlets. When I compile my serverlet I get follwoing error
    cannot find mymbol method parseDate(java. lang.String)

    I have follwoing code:

    Code: ( text )
    package admin;

    import java.lang.Objec t.*;
    import java.util.*;
    import java.io.IOExcep tion;
    import data.*;
    import business.*;
    import javax.servlet.R equestDispatche r;
    import javax.servlet.S ervletException ;
    import javax.servlet.h ttp.HttpServlet ;
    import javax.servlet.h ttp.HttpServlet Request;
    import javax.servlet.h ttp.HttpServlet Response;


    public class AddPaymentServl et extends HttpServlet{
    public void doGet(HttpServl etRequest request, HttpServletResp onse response) throws IOException, ServletExceptio n{
    // Payment information

    String paymentID = request.getPara meter("paymentI D");
    String clientID = request.getPara meter("clientID ");
    String paymentType = request.getPara meter("paymentT ype");
    String paymentAmount = request.getPara meter("paymentA mount");
    String paymentStartDat e = request.getPara meter("paymentS tartDate");
    String paymentExpiryDa te = request.getPara meter("paymentE xpiryDate");
    String paymentDescript ion = request.getPara meter("paymentD escription");
    String paymentState = request.getPara meter("paymentS tate");


    //Integer.parseIn t()
    // get old Payment object from session
    Payment newPayment = new Payment(Integer .parseInt(payme ntID),Integer.p arseI nt(clientID),pa ymentType,Doubl e.parseDouble(p aymen tAmount),Date.p arseDate(paymen tStartDate),Dat e.par seDate(paymentE xpiryDate),paym entDescription, Boole an.parseBoolean (paymentState)) ;
    // PaymentDescript ion,Double.pars eDouble(unitPri ceSma ll),Double.pars eDouble(unitPri ceMedium), Double.parseDou ble(unitPriceLa rge));
    // update Payment information
    PaymentDB.addRe cord(newPayment );

    // over-write Payment object in session
    request.getSess ion().setAttrib ute("payment",n ewPayment);
    request.getSess ion().setAttrib ute("payments", PaymentDB.readR ecords());

    RequestDispatch er dispatcher = getServletConte xt().getRequest Dispatcher("/Admin/payments.jsp");
    dispatcher.forw ard(request, response);
    }
    public void doPost(HttpServ letRequest request, HttpServletResp onse response) throws IOException, ServletExceptio n{
    doGet(request, response);
    }


    }


    Problem lies here:


    Code: ( text )
    Payment newPayment = new Payment(Integer .parseInt(payme ntID),Integer.p arseI nt(clientID),pa ymentType,Doubl e.parseDouble(p aymen tAmount),Date.p arseDate(paymen tStartDate),Dat e.par seDate(paymentE xpiryDate),paym entDescription, Boole an.parseBoolean (paymentState)) ;



    I need help why it's like that?
    Thanks
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    This has got nothing to do with JSP/servlets. You are just assuming a method exists when it doesn't. Class java.util.Date doesn't have a method called parseDate. The proper was to parse dates is to use DateFormat or SimpleDateForma t:

    Comment

    • creative1
      Contributor
      • Sep 2007
      • 274

      #3
      thanks for replying.
      I am trying this now
      Code:
      Payment newPayment = new Payment(Integer.parseInt(paymentID),Integer.parseInt(clientID),paymentType,Double.parseDouble(paymentAmount),DateFormat(paymentStartDate),DateFormat(paymentExpiryDate),paymentDescription,Boolean.parseBoolean(paymentState));

      still getting error

      Comment

      • BigDaddyLH
        Recognized Expert Top Contributor
        • Dec 2007
        • 1216

        #4
        Set this code aside and try to write a simple program -- only a few lines long -- that tries to parse a String into a Date. Note that DateFornat and SimpleDateForma t are classes, so what you wrote makes no sense.

        Comment

        • creative1
          Contributor
          • Sep 2007
          • 274

          #5
          thanks, I got what you mean . problem was I did not knew how to work with that class. I was expecting it would be already defined like int.parseInt().
          thanks buddy

          Comment

          • BigDaddyLH
            Recognized Expert Top Contributor
            • Dec 2007
            • 1216

            #6
            Originally posted by creative1
            thanks, I got what you mean . problem was I did not knew how to work with that class. I was expecting it would be already defined like int.parseInt().
            thanks buddy
            It's important to read the API rather than guessing. Guessing has a low success rate.

            Comment

            Working...