JSP Getting Started

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    JSP Getting Started

    I have a subject that covers JSP(new to me), accessing database through JSP(new to me), applets, UML(also new to me)

    So, as im learning java, all i did to learn faster is i've created some applications(wi th sense). With my style of self learning, i hope it could be effective in JSP too....

    I like to be advanced on the planned topic to be discussed by our instructor(He is not a certified Java Programmer though)

    So now, all i know about JSP is the following:
    -basic tags
    expression <%= something%>
    declaration <%! something%>
    i dont know the term <% something %> I think it is an invocation
    equivalent to java (Please correct me on that part)

    -Setting up tomcat.
    -The ROOT folder
    -WEB-INF theoritically knew where to put classes/jars etc....
    (though im not tested them yet)
    -getting the value of a html form through request.getPara meter("form input-type name)

    Those are basics obviously...( I learned them through surfing)

    And im planning to create a simple application.
    What comes on my mind is to reimplement my previous project (Simple Hotel FrontDesk System) into Online Hotel Reservation System
    -the registration is obviously done by the hotel frontdesk only....
    -Maybe the BlackList feature would be added if i knew the real ( Deep )

    Actually, we have proposed a project "Online Entrance Exam" to our instructor and he likes it... so he approved our proposal.....( Not Thesis )

    But before we start banging that project, deadline is on October ( Final week in this semester )

    I like to grasp the essentials of JSP and also the other techniques, new way, and theory behind that architectural design for web application platform....
    (Please correct me on the phrase above)

    Actually, the faculty decided to order a J2EE book from Sun( i think the book base is in Singapore) for about 2500php or $56.00

    Unfortunately, that book is expected to be arrived on midterms.... unbelievable scenario(but that was true)....

    I did attempt to buy a new book instead of waiting that precious book, but i doubt for having such book....(for $40.99)....

    So i decided to wait that precious book, yet learning in advance from this forum and the other web resources....

    What a long story :)

    Well, anyway,

    Here is what i suppose to know in JSP as im building my experimental application for the supplement on my final project( Not thesis though )

    I like to know about the JSP Beans,

    for example, i have a java class that contains setter and getter methods,
    i like to jar them, unfortunately, i didn't found the right tutorial for it on the web...

    so can you post a helpful url that would teach me how to do that?
    and also, about how to access the jar file from the jsp container( doubt of terms )Please correct me....

    Or can you show an example?
    For example, i have a jar file in WEB-INF/lib/JARZKY.jar
    and the content is com\myclass.cla ss(with setSetter() and getGetter() methods)

    How can you invoke that class through JSP?


    A sincere Java Lover,
    sukatoa
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    First read this one.
    Then get this one which is free from sun for the more serious stuff.

    Comment

    • sukatoa
      Contributor
      • Nov 2007
      • 539

      #3
      Originally posted by r035198x
      First read this one.
      Then get this one which is free from sun for the more serious stuff.
      Thanks for the URL r035198x....
      Im on my way.....

      Comment

      • sukatoa
        Contributor
        • Nov 2007
        • 539

        #4
        Originally posted by sukatoa
        Thanks for the URL r035198x....
        Im on my way.....
        I have created a jar named Checker.jar
        saved on WEB-INF\lib\

        my problem is i cannot access the Checker.jar
        with content dma.Checker.cla ss

        i've attempt:

        <jsp:useBean id="Checker" scope="page" class="Checker" />

        attempting to replace class into jar ==> invalid attribute

        But i really have no idea how to fix this.....

        Can you show me an example about this?
        The url above does only explains how to deal with classes...( not jar )

        Comment

        • sukatoa
          Contributor
          • Nov 2007
          • 539

          #5
          Is this possible?

          I would like to add a text file together with the classes folder inside WEB-INF
          And that text-file is the source to be extracted for calculations and i will try to open that textfile from my java-bean.... possible? or not?

          for example,
          I have a text file that contains the list of all countries....
          That is really disapointing on my part that all the countries will be coded on
          bean. so i decided not to do it inside the code, instead on the database....
          But for that it is just a constant data, having it on the database will add
          another table and it will consume another bean that has 100 lines of code
          (Approximately) . Before attempting it into database, i need your advice, and
          the answer on the above questions experts....

          Looking forward on your replies,
          sukatoa....

          Comment

          • sukatoa
            Contributor
            • Nov 2007
            • 539

            #6
            Im currently doing some experiments in JSP........

            and I fail to debug my code.....

            Here is the stacktrace:
            Code:
            org.apache.jasper.JasperException: For input string: ""
            	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:370)
            	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
            	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
            	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
            
            
            root cause 
            java.lang.NumberFormatException: For input string: ""
            	java.lang.NumberFormatException.forInputString(Unknown Source)
            	java.lang.Integer.parseInt(Unknown Source)
            	java.lang.Integer.valueOf(Unknown Source)
            	org.apache.jsp.home.guests.Validator_jsp.checkAccountInformation(org.apache.jsp.home.guests.Validator_jsp:63)
            	org.apache.jsp.home.guests.Validator_jsp._jspService(org.apache.jsp.home.guests.Validator_jsp:270)
            	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
            	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
            	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
            	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
            	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
            	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
            I am curious about that inputString.... .....

            Here is the JSP code.

            [CODE=JAVA]<%@ page
            contentType="te xt/html;
            charset=iso-8859-1"
            language="java"
            errorPage=""

            import = "beans.specific .constants.Imag eRefGenerator"
            import = "beans.reusable .checker.EmailC hecker"
            import = "java.util.Arra yList"
            import = "java.util.Greg orianCalendar"
            %>
            <jsp:useBean id="signupcooki e" class="beans.sp ecific.cookies. SignUpCookie" scope="session" />

            <%!
            ImageRefGenerat or img = new ImageRefGenerat or();
            String SenderLocation = "http://localhost:8080/home/guests/register.jsp";
            EmailChecker checkemail = new EmailChecker();
            ArrayList<Strin g> reminder = new ArrayList<Strin g>();

            private final boolean checkVerificati on(String confirm,String reference,boole an strict){
            if(confirm.leng th()>0){
            if(!strict)
            return confirm.equalsI gnoreCase(refer ence);
            else
            return confirm.equals( reference);
            }else{
            return false;
            }
            }

            private final boolean checkMail(Strin g email){
            checkemail.rese tValue(email);
            return checkemail.chec kStoredEmail();
            }

            private final boolean checkAccountInf ormation(String username,
            String password,
            String verifypassword,
            String emailaddress,
            String verifyemailaddr ess,
            String creditcardnumbe r){
            boolean confirmer = true;
            if(username.len gth()==0){
            reminder.add("u sername");
            confirmer = false;
            }
            if(password.len gth()<6){
            reminder.add("p assword");
            confirmer = false;
            }
            if(!checkVerifi cation(password ,verifypassword ,true)){
            reminder.add("v erifypassword") ;
            confirmer = false;
            }
            if(!checkMail(e mailaddress)){
            reminder.add("e mail");
            confirmer = false;
            }
            if(!checkVerifi cation(emailadd ress,verifyemai laddress,true)) {
            reminder.add("v erifyemail");
            confirmer = false;
            }
            if(Integer.valu eOf(creditcardn umber)<16){
            reminder.add("c cnumber");
            confirmer = false;
            }
            return confirmer;
            }

            private final boolean checkMemberInfo rmation(String surname,
            String firstname,
            String middlename,
            String homeadd,
            String birthdate,
            String gender,
            String country,
            String passport,
            String placeissue){
            boolean confirmer = true;
            if(surname.leng th()==0){
            reminder.add("s urname");
            confirmer = false;
            }
            if(firstname.le ngth()==0){
            reminder.add("f irstname");
            confirmer = false;
            }
            if(middlename.l ength()==0){
            reminder.add("m iddlename");
            confirmer = false;
            }
            if(homeadd.leng th()==0){
            reminder.add("h omeaddress");
            confirmer = false;
            }
            if(!checkBirthD ate(birthdate)) {
            reminder.add("b irthdate");
            confirmer = false;
            }
            if(gender.equal s("Select")){
            reminder.add("g ender");
            confirmer = false;
            }
            if(country.equa ls("Select Country")){
            reminder.add("c ountry");
            confirmer = false;
            }
            if(passport.len gth()==0){
            if(placeissue.l ength()>0){
            reminder.add("p assportnumber") ;
            confirmer = false;
            }
            }else{
            if(placeissue.l ength()==0){
            reminder.add("p laceissue");
            confirmer = false;
            }
            }
            return confirmer;
            }

            private final boolean checkContactInf ormation(String landline,
            String mobile,
            String fax,
            String alteremail){
            boolean ret = true;
            if(landline.len gth()!=0||mobil e.length()!=0||
            fax.length()!=0 ||alteremail.le ngth()!=0){
            if(alteremail.l ength()>0){
            if(!checkMail(a lteremail)){
            reminder.add("a lteremail");
            ret = false;
            }
            }
            }else{
            reminder.add("n onecontactinfo" );
            ret = false;
            }
            return ret;
            }

            private final boolean checkBirthDate( String data){
            String month = data.split("-")[0];
            Integer day = Integer.valueOf (data.split("-")[1]);
            Integer year = Integer.valueOf (data.split("-")[2]);
            boolean ret = true;

            if(month.equals ("February") ){
            if(new GregorianCalend ar().isLeapYear (year))
            ret=day>28?fals e:ret;
            else
            ret=day>29?fals e:ret;
            }

            if(month.equals ("April")||mont h.equals("June" )||month.equals ("September" )||
            month.equals("N ovember"))
            ret = day==31?false:r et;
            return ret;
            }

            private final void VoidVerificatio n(){
            reminder.add("r emoteuser");
            }
            %>

            <%
            signupcookie.re setInstance();

            String username = request.getPara meter("username ");
            String password = request.getPara meter("password ");
            String checkpassword = request.getPara meter("checkpas sword");
            String emailaddress = request.getPara meter("emailadd ress");
            String checkemail = request.getPara meter("checkema il");
            String creditcard = request.getPara meter("creditca rd");

            String surname = request.getPara meter("surname" );
            String firstname = request.getPara meter("firstnam e");
            String middlename = request.getPara meter("middlena me");

            String month = request.getPara meter("month");
            String day = request.getPara meter("day");
            String year = request.getPara meter("year");
            String gender = request.getPara meter("gender") ;
            String homeaddress = request.getPara meter("homeaddr ess");
            String companyaddress = request.getPara meter("companya ddress");

            String country = request.getPara meter("country" );
            String passportnumber = request.getPara meter("passport number");
            String passportissue = request.getPara meter("passport issue");

            String landline = request.getPara meter("landline ");
            String mobile = request.getPara meter("mobile") ;
            String faxnumber = request.getPara meter("faxnumbe r");
            String altermail = request.getPara meter("altermai l");

            String confirmation = request.getPara meter("confirma tion");
            String ref = request.getPara meter("ref");

            signupcookie.se tUsername(usern ame);
            signupcookie.se tEmailAddress(e mailaddress);

            signupcookie.se tSurname(surnam e);
            signupcookie.se tFirstname(firs tname);
            signupcookie.se tMiddlename(mid dlename);
            signupcookie.se tBirthDate(mont h,day,year);
            signupcookie.se tGender(gender) ;
            signupcookie.se tHomeAddress(ho meaddress);
            signupcookie.se tCompanyAddress (companyaddress );

            signupcookie.se tCountry(countr y);
            signupcookie.se tPassportNumber (passportnumber );
            signupcookie.se tPassportIssue( passportissue);

            signupcookie.se tLandline(landl ine);
            signupcookie.se tMobile(mobile) ;
            signupcookie.se tFaxNumber(faxn umber);
            signupcookie.se tAlterEmail(alt ermail);

            String validValue = img.getValue(re f);

            boolean indicator = true;
            String brtdate = month.concat("-"+day).conc at("-"+year);


            if(!checkAccoun tInformation(us ername,password ,checkpassword,
            emailaddress,ch eckemail,credit card)){
            indicator = false;
            }
            if(!checkMember Information(sur name,firstname, middlename,home address,brtdate ,
            gender,country, passportnumber, passportissue)) {
            indicator = false;
            }
            if(!checkVerifi cation(confirma tion,validValue ,false)){
            VoidVerificatio n();
            indicator = false;
            }

            if(!indicator){
            response.sendRe direct(SenderLo cation);
            }
            %>
            [/CODE]

            Im loosing hope with this problem.....

            Im using DreamWeaverMX, manual set-up of Apache Tomcat........

            Can you experts tell me where is it on the code?
            Or can you suggest any alternatives for this?

            waiting,
            sukatoa

            Comment

            • sukatoa
              Contributor
              • Nov 2007
              • 539

              #7
              Im always late to realize........ .

              ArrayList indexOf(Object o) uses the equals method that can't be used to compare null values........

              Gotcha!!!!!!!

              [CODE=JAVA]final boolean hasReminder(Str ing exists){
              boolean ret = false;
              reminderloop:
              for(String rem:reminder){
              if(rem.equals(e xists)){
              ret = true;
              break reminderloop;
              }
              }
              return ret;
              }[/CODE]

              I wonder what implementation did lastIndexOf method used in ArrayList?
              Is that only uses the reverse value arrangement then apply the indexOf method?

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Originally posted by sukatoa
                I wonder what implementation did lastIndexOf method used in ArrayList?
                Is that only uses the reverse value arrangement then apply the indexOf method?
                If you wonder how those standard classes implemented things go to your jdk
                directory and find the file src.zip. It's a zip file that contains all the source code
                files for all the publicly available classes in your Java installation.

                kind regards,

                Jos

                Comment

                • sukatoa
                  Contributor
                  • Nov 2007
                  • 539

                  #9
                  Just a quick,

                  I've planned to implement all the necessary validations using JSP,

                  Now, may i know what are the disadvantages of doing such thing?
                  except for the passing parameters?( takes a little bit of time ) through form.....

                  Unlike JS, that it runs on the browser as it validates the form just in time.......

                  Comment

                  • ajos
                    Contributor
                    • Aug 2007
                    • 283

                    #10
                    Originally posted by sukatoa
                    Just a quick,

                    I've planned to implement all the necessary validations using JSP,

                    Now, may i know what are the disadvantages of doing such thing?
                    except for the passing parameters?( takes a little bit of time ) through form.....

                    Unlike JS, that it runs on the browser as it validates the form just in time.......
                    I think by validations you mean form validations? I normally do it in the client side as well as in the server side(just to be doubly sure, and thats the way it should be :)). I dont see it as a disadvantage because those are the things a web developer should do, lets say what happens when a ignorant(or any user) turns the javaScript off in the browser? I as a web developer ensure that the user doesnt skip the mandatory things that he needs to fill. I dont think that it comes down to performance, its a securuty thing for me.

                    regards,

                    ajos

                    Comment

                    • r035198x
                      MVP
                      • Sep 2006
                      • 13225

                      #11
                      Originally posted by ajos
                      I think by validations you mean form validations? I normally do it in the client side as well as in the server side(just to be doubly sure, and thats the way it should be :)). I dont see it as a disadvantage because those are the things a web developer should do, lets say what happens when a ignorant(or any user) turns the javaScript off in the browser? I as a web developer ensure that the user doesnt skip the mandatory things that he needs to fill. I dont think that it comes down to performance, its a securuty thing for me.

                      regards,

                      ajos
                      Yes, always do validations both client side and server side. It's one of the golden rules of web programming.

                      Comment

                      • JosAH
                        Recognized Expert MVP
                        • Mar 2007
                        • 11453

                        #12
                        Originally posted by r035198x
                        Yes, always do validations both client side and server side. It's one of the golden rules of web programming.
                        Just a question: while I do understand that just client side validation would be
                        silly (no Javascript, request synthesis etc.) but what's wrong with just having
                        server side validation? (except for the server load).

                        kind regards,

                        Jos

                        ps. sorry for the hijack.

                        Comment

                        • r035198x
                          MVP
                          • Sep 2006
                          • 13225

                          #13
                          If there's client side validations as well then the user doesn't have to wait for the page to be posted to the server just to be told that they left a field blank.

                          Comment

                          • JosAH
                            Recognized Expert MVP
                            • Mar 2007
                            • 11453

                            #14
                            Originally posted by r035198x
                            If there's client side validations as well then the user doesn't have to wait for the page to be posted to the server just to be told that they left a field blank.
                            Ah, ok; so the reason for double sided validation is just speed. But then you have
                            to keep both validations in sync with each other. (just wondering)

                            kind regards,

                            Jos

                            Comment

                            • r035198x
                              MVP
                              • Sep 2006
                              • 13225

                              #15
                              Originally posted by JosAH
                              Ah, ok; so the reason for double sided validation is just speed. But then you have
                              to keep both validations in sync with each other. (just wondering)

                              kind regards,

                              Jos
                              Can become a nightmare right? Generally the server side validator must not assume any client side validators. So his job is easier. He doesn't need to sync with anyone. The client side validator only needs to do the best he can to make sure that the server code is not called unnccessarily.

                              Comment

                              Working...