Results 1 to 3 of 3

Thread: Pls Help

  1. #1
    vhannierose is offline Member
    Join Date
    Nov 2007
    Location
    taguig city, philippines
    Posts
    4
    Rep Power
    0

    Post Pls Help

    Hi! I'm currently having my J2EE training and I need help with this. Thanks in advance.

    1.) Create a project in Eclipse. Name it ServletActivity 3 – Shopping Cart Application.

    2.) Create a servlet (name it LoginServlet.java). This servlet outputs html code to the browser. The output should be a simple login page (See Screenshot 1). The servlet should retrieve the last login username from the cookies. If a user has logged-in before, display the username (See Screenshot 2), otherwise, display an empty username field.

    3.) Create another servlet and name it DoLoginServlet.java. This servlet is called after clicking “Submit” button in LoginServlet.java. If the user inputs an empty username or an empty password, display an error message (See Screenshot 3). Otherwise, display the available items for sale (See Screenshot 4). In this servlet, place the username in the session. Also, create a cookie object and place it in the response. By placing the username inside a cookie, you can now keep track of the last username who have logged-in in the application per browser. Also, by placing the username inside the session, the next servlets can now authenticate users who have logged-in.

    4.) Create another servlet and name it DoPurchaseServlet.java. This servlet checks the last action from DoLoginServlet.java, either the user submitted his purchases (Submit) or has cancelled (Logout). If the user sumitted his purchase/s (Submit) display the items that the user has selected in Screenshot 4 and ask for his credit card number for the payment of his items (See Screenshot 5). If the user cancelled his purchases, redirect the user to LoginServlet.java thus display Screenshot 2. Also, check if there’s a user who is currently logged-in, otherwise, redirect the user to LoginServlet.java. Through this way users can’t directly jump to DoPurchaseServlet.java without logging in first.

    5.) Create another servlet and name it DoPaymentServlet.java. Check also if the last action was Submit or Logout (from DoPurchaseServlet.java). If he chooses to Logout redirect him to LoginServlet.java. If he chooses to Submit, display a thank you page if he has submitted his credit card number (See Screenshot 6). Again, check if there’s a user who have currently logged-in in the application, if none, redirect him to LoginServlet.java.

    6.) Configure the servlets in web.xml and deploy and test the application.

  2. #2
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    What exactly do you need help with? You appear to have pretty detailed directions laid out for you. Attempt them, show us you what you attempted and then we are in a better position to assist you.

  3. #3
    vhannierose is offline Member
    Join Date
    Nov 2007
    Location
    taguig city, philippines
    Posts
    4
    Rep Power
    0

    Smile Hi! Need your help again

    Hi Guys,

    I need a help in these one. Actually, I’m a newbie and I’ve been working with this problem. Please help. Thanks.

    • Handle exceptions for getting sex description
    a. Throw exception for undefined codes
    Tip: throw a new Exception with the error description as parameter
    b. Catch the exception and return the error description to the caller
    Tip: extract the Exception message
    • Handle exceptions for getting civil status description
    a. Throw exception for undefined codes
    b. Catch the exception and return the error description to the caller
    • Handle exceptions for getting employee type description
    a. Throw exception for undefined codes
    b. Catch the exception and return the error description to the caller
    • Handle exceptions for computing monthly salary
    a. Throw exception for zero or negative salary
    b. Catch the exception and propagate the exception to the calling method
    Tip: declare throws clause in the method signature
    • Catch the exception in the main() method and handle the exception by printing the stack trace before stopping the program execution
    1. Set employee attributes to invalid test data to create the error situation

    Thanks in advance!




    public class EmployeeMain {

    public static void main(String[] args) {

    String name = "Vanessa Rose V. Castro"; //for name
    String address = "Taguig City"; //for address

    System.out.println("Name: " + name);
    System.out.println("Address: " + address);
    System.out.println ("Sex: " + EmployeeMain.getsexCode());
    System.out.println("Civil Status Code: " + EmployeeMain.getcivilStatusCode());
    System.out.println ("Employee Type: " + EmployeeMain.getemployeeStatusCode());
    System.out.println("Birthdate: " + EmployeeMain.getbirthMonth() + " " + EmployeeMain.getbirthDay() + ", " + EmployeeMain.getbirthYear());
    System.out.println ("Date Hired: " + EmployeeMain.gethiredMonth() + " " + EmployeeMain.gethiredDay() + ", " + EmployeeMain.gethiredYear());
    System.out.println ("Monthly Salary: " + EmployeeMain.getmonthlySalary());

    char sex = 'F'; //for sex
    char civilStatus = 'S'; //for civil status
    char employeeStatus = 'R'; //for employee status

    int basicSalary = 10000;
    int ot = 150;
    double tax = basicSalary*0.10; // assume witholding tax is 10% of salary
    double deductions = 500; //example: SSS, others
    double monthlySalary = basicSalary + ot - tax - deductions;

    // added for activity 1 run 2
    int yyyy=1985, mm=01, dd=25; //birth date
    String mmm = mm==1?"January":mm==2?"February":mm==3?"March":mm= =4?"April":mm==5?"May":mm==6?"June":
    mm==7?"July":mm==8?"August":mm==9?"September":mm== 10?"October":mm==11?"November":mm==12?"December":" Unknown";
    int yyyy1=2007, mm1=8, dd1=21; // hired date
    String mmm1 = mm1==1?"January":mm1==2?"February":mm1==3?"March": mm1==4?"April":mm1==5?"May":mm1==6?"June":
    mm1==7?"July":mm1==8?"August":mm1==9?"September":m m1==10?"October":mm1==11?"November":mm1==12?"Decem ber":"Unknown";

    }

    static String getsexCode () {
    char sex = 'F';
    String sexCode = sex=='F'?"Female":sex=='M'?"Male":"Unknown";
    return sexCode;
    }


    static String getcivilStatusCode () {
    char civilStatus = 'S';
    String civilStatusCode = civilStatus=='S'?"Single":civilStatus=='M'?"Marrie d":civilStatus=='O'?"Others":"Unknown";
    return civilStatusCode;
    }

    static String getemployeeStatusCode () {
    char employeeStatus = 'R';
    String employeeStatusCode = employeeStatus=='R'?"Regular":employeeStatus=='P'? "Probationary":employeeStatus=='C'?"Contractual":" Unknown";
    return employeeStatusCode;
    }

    static double getmonthlySalary () {
    int basicSalary = 10000;
    int ot = 150;
    double tax = basicSalary*0.10; // assume witholding tax is 10% of salary
    double deductions = 500; //example: SSS, others
    double monthlySalary = basicSalary + ot - tax - deductions;
    return monthlySalary;
    }

    //for birth date
    static int getbirthYear () {
    int yyyy=1985, mm=01, dd=25; //birth date
    return yyyy;
    }

    static String getbirthMonth () {
    int yyyy=1985, mm=01, dd=25; //birth date
    String mmm = mm==1?"January":mm==2?"February":mm==3?"March":mm= =4?"April":mm==5?"May":mm==6?"June":
    mm==7?"July":mm==8?"August":mm==9?"September":mm== 10?"October":mm==11?"November":mm==12?"December":" Unknown";
    return mmm;
    }

    static int getbirthDay () {
    int yyyy=1985, mm=01, dd=25; //birth date
    return dd;
    }

    //for date hired
    static int gethiredYear () {
    int yyyy1=2007, mm1=01, dd1=21; //hired year
    return yyyy1;
    }

    static String gethiredMonth () {
    int yyyy1=1985, mm1=8, dd=21; //hired month
    String mmm1 = mm1==1?"January":mm1==2?"February":mm1==3?"March": mm1==4?"April":mm1==05?"May":mm1==6?"June":
    mm1==07?"July":mm1==8?"August":mm1==9?"September": mm1==10?"October":mm1==11?"November":mm1==12?"Dece mber":"Unknown";
    return mmm1;
    }

    static int gethiredDay () {
    int yyyy1=1985, mm1=01, dd1=21; //hired day
    return dd1;
    }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •