Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,149,970 members, 7,806,812 topics. Date: Wednesday, 24 April 2024 at 01:34 AM

JSP Web Development - Programming (2) - Nairaland

Nairaland Forum / Science/Technology / Programming / JSP Web Development (5706 Views)

100+ Java, JS & JSP Apps With Their Source Code That You Can Make Money With / HTML And Jsp / Java Server Pages (jsp) Or Java Server Face(jsf Which Path To Trend? ? ? ? (2) (3) (4)

(1) (2) (Reply) (Go Down)

Re: JSP Web Development by soulonfire(f): 5:17pm On Mar 21, 2007
@sbuscribe U R SUCH A BLESSING!! Thank u for this thread, im a newbie to java and the programming entity generally, but your explanation is so detailed, thanks soo much. smiley

@sbucareer oops!! i'm soo sorry i muddled up the identity (subsribe instead of sbucareer), thanks neeways wink
Re: JSP Web Development by sbucareer(f): 8:05pm On Mar 21, 2007

Thank you soulonfire, I am glad that I was able to help and reach out to many people. If anyone finds discrepancy within this trail, please point out so we can correct it.

This trail is not just only sbucareer contributions, anyone is very much welcome to contribute possitive thoughts. Learning has NEVER been only one man show, please feel free to contribute not adjudicate to any positive contributions people have made.
Re: JSP Web Development by sbucareer(f): 8:10pm On Mar 21, 2007

<%-- Save this file as pizza.jsp --%>>

<%@ page contentType="text/html"%>
<%@ page import="com.nairaland.beans.Pizza"%>

<HTML>
<HEAD>
<TITLE>Pizza Bean</TITLE>
</HEAD>
<BODY>
   <jsp:useBean id="pizza" class="com.nairaland.beans.Pizza" scope="page"/>

<center><h1>Order Pizza</h1></center>



<form name="pizza" action="process.jsp" method="POST">

<table border="0">
<tr>
<td><b>Name:</b></td>
<td><input type="text" name="name" size="25"></td></br>
</tr><tr>

<td><b>Address:</b></td>
<td><input type="text" name="address" size="30"></td></br>
</tr><tr>

<td><input type="radio" name="purchaseType" value="Home Delivery"></td>
<td><b> <jsp:getProperty name="pizza" property="purchaseType" value="0"/> </b></td></tr>

<tr>
<td><input type="radio" name="purchaseType" value="Take Away"></td>
<td><b><jsp:getProperty name="pizza" property="purchaseType" value="1"/></b></td></tr>

<tr>
<td><b>Select your pizza(s), </b></td>
</tr>

<tr>
<td><input type="checkbox" name="pepperoni" value="Yes"></td>
<td><b><jsp:getProperty name="pizza" property="pepperoni" /></b></td></tr>
<br/>

<tr>
<td><input type="checkbox" name=hawaiian value="Yes"></td>
<td><b><jsp:getProperty name="pizza" property="hawaiia" v/></b></td></tr>


<tr>
<td><input type="checkbox" name="margherita" value="Yes"></td>
<td><b><jsp:getProperty name="pizza" property="margherita" /></b></td></tr>

<tr>
<td><input type="submit" value="Place Order"></td></tr></table>
</form>


</BODY>
</HTML>


If you look at the HTML form control we said goto process.jsp page. We will create a Process.jsp and over write the bean content. We are just playing with JSP, in real live we would not need to hard code JavaBean like we did and use the getProperty to update out HTML. We could, if we have a genuine reason to do so.


<%-- Save this file as process.jsp --%>

<%@ page contentType="text/html"%>
<%@ page import="com.nairaland.beans.Pizza"%>

<HTML>
<HEAD>
<TITLE>Pizza Bean</TITLE>
</HEAD>
<BODY>
   <jsp:useBean id="pizza" class="com.nairaland.beans.Pizza" scope="page"/>
   <jsp:setProperty name="pizza" property="*"/>

   <b>Name</b>
<jsp:getProperty name="pizza" property="name" value=""/>

<br/>
<b>Address</b>
<jsp:getProperty name="pizza" property="address" value=""/>

<br/>
<b>Delivery</b>
<jsp:getProperty name="pizza" property="purchaseType" value=""/>

<br/>
<b>Pepperoni</b>
<jsp:getProperty name="pizza" property="pepperoni" value=""/>

<br/>
<b>Margherita</b>
<jsp:getProperty name="pizza" property="margherita" value=""/>

<br/>
<b>Hawaiian</b>
<jsp:getProperty name="pizza" property="hawaiian" value=""/>

<br/>
</BODY>
</HTML>

You will notice that the value of <jsp:getProperty name="pizza" property="name" value=""/> is set to empty that will reset the property to empty value.


Re: JSP Web Development by sbucareer(f): 8:39pm On Mar 21, 2007

Ok let me explain what is going on here. You will see that Pizza.jsp is just our normal HTML file, just that I have coded the JavaBean class Pizza.java and try to retrieve the values into the HTML file. We do not need to do that.

As you can see I have reset all the value of the bean to empty in process.jsp. by setting value="". Now, the Pizza.jsp simply collect data from the front-end and sent it back to the back-end using HTML form control. i.e.

<form name="pizza" action="process.jsp" method="POST">

Now, the process.jsp is where it gets interesting. As you can recall, we instantiated the Pizza.java bean using this tomcat specification

<jsp:useBean id="pizza" class="com.nairaland.beans.Pizza"/>

What the above code is saying is that, please instantiate Pizza.java for me using pizza as the object reference. Like in our Java programming we would say

Pizza pizza = new Pizza();

We are saying the instance of Pizza.java should be refer to as pizza using the id tag i.e id="pizza". Now, anywhere we want to use Pizza.java we would use the name pizza.

Remember that we could have given id="pizza" and name i.e. id="usa" etc. But it would confuse you or the guy who would maintain it later when you use lots of beans within on page.

As we have instantiated it, we use the <jsp:setProperty name="pizza" property="*"/> to set all the data we collected from the front-end. Don't worry about how it works the tomcat container takes care of it.

The thing is that the property is set to * i.e property="*" which instruct the container to populate all the value to the Bean. You can set them one by one i.e

<jsp:setProperty name="pizza" proptery=marghrita" value="Yes"/>

Note, the JavaBean follow some convention before all thses can work like attributes name and methods name. If you have an attribute name call telephone i.e.

String telephone =  null;

You MUST have a setter and gettter called

setTelephone(){}

getTelephone(){}

set and get MUST be appended at the begining of the attribute name. The case MUST be small letters i.e set and get follow by a capital letter of the attribute's name i.e. Telelphone.

If you don't follow this convention, your JavaBean will not work and you will run into issues. Now that we have clear the air, try and play around with JavaBeans.

Note, you can do this in your JSP file when you use
<use:Beans id="pizza"  class="com.nairaland.beans.Pizza" scope="application"/> toinstantiate your beans

<%=pizza.setMarghrita("True"wink%>

<%=pizza.getName()%>

pizza is the object reference to your bean class. Also remember that you MUST compile your bean and make the Pizza.class available int the C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ROOT\WEB-INF\classes directory.

The container do no use java class, it uses the bytecode i.e. Pizza.class.
Re: JSP Web Development by sbucareer(f): 9:28pm On Mar 21, 2007


<jsp:useBean id="theBean" class="com.org.sun.bean.TheBean" scope="application"/>

There are four types of bean visibility:

1. Page
2. Request
3. Session
4. Application

These are called application scope. Why use application scope? Well it is essential when writing large application so that an instance of a bean is always available to other page too, so that instead of always creating a new bean instance the action will first look at to see if the bean matching the specified name and scope already exites.

page scope: Available to the handling page only.

request scope: Available to handling page and any page to which it passess control

seesion scope: Available to any JSP within the same session i.e. webapp

application scope: Available to any component of the same web application

These scope are useful particularly when you need to instantiate a database object only once and pass control to other pages within the same web application. i.e. multiple webapps
Re: JSP Web Development by sbucareer(f): 9:41pm On Mar 21, 2007
[size=24pt]
Creating Database with Java
[/size]

What is database
"The term or expression database originated within the computer industry. Although its meaning has been broadened by popular use, even to include non-electronic databases, this article takes a more technical perspective towards the topic. Database like records have been in existence since well before the industrial revolution in the form of ledgers, sales receipts and other business related collections of data. A possible definition is that a database is a structured collection of records or data which is stored in a computer so that a program can consult it to answer queries. The records retrieved in answer to queries become information that can be used to make decisions. The computer program used to manage and query a database is known as a database management system (DBMS). The properties and design of database systems are included in the study of information science." 1

The definition above is just too good. It says something about database being a structured collection of records or data which is stored in a computer so that a program can consult it to answer queries

When he said program I know you mind must have directed you to Java. Java provides some set of API's that actually allows you to interact with database. i.e. javax.sql.*

Database is made up of two lanaguages

1. DDL (Data Definition Language)
2. DML (Data Manipulation Language)

DDL, is used by database developer or engineers to design and build database while DML is used by administrator or programmer to query the database DDL.

These two languages takes different shape and forms depending on the database. But the DML was agreed by Database consortium to achive compactibilty to use SQL for DML. Even, many vendors still have their own version of SQL.

SQL is  sequential query language used by programmers or DBA (Database Administrator) to query the information stored in a database.

Because the engine that processes DML is incompactible with many language, Java came up with interface called JDBC (Java DataBase Connectivity) with many API's to interact with DML.

For this trail we are going to use Access database as a benchmark for newbies following the trail. If you have used database before, use can download and use MYSQL. although the content page said we are going to use MYSQL, it is up to you to let me know which one you want.

I am looking at the configuration issues, because in the past many people have shown difficulties with configuration. Microsoft operating systems comes with JDBC by default. We will use ODBC (Object Database Connectivity) with is microsoft API's for DML interface to bridge our JDBC to interact with Access database. You MUST have access database installed on you Pc to follow this.

If you want to use MYSQL, download and install the later version excluding any beta. Find MYSQL JDBC driver, download and install the driver at a prefered location and copy the driver (usually a jar file to) C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib and set the jar file to the CLASSPATH i.e

MYSQL_HOME=C:\mysq_connector4.1
PATH=;%MYSQL_HOME%\bin
CLASSPATH=C:\mysq_connector4.1\lib\jdbc.jar

These are just a guide, I really do not know their names and directories. I use Oracle. Oracle is difficult to install and configure. With a dialup connection it would probably take you 3days to download.

Have a go with MYSQL, if you have issues let me know.

Re: JSP Web Development by sbucareer(f): 10:44pm On Mar 21, 2007

You MUST know SQL to fully understand or follow this trail. SQL is out of the scope of this trail, but you can familiarize yourself with SQL and come baack to follow the trail. You do not need to study and become a DBA to follow this trail. All you would need is to understand

1. SELECT
2. WHERE
3. DELETE
4. UPDATE
5. CREATE

If you can understand these SQL syntax you would follow very perfectly. Below is how to set up JDBC with Microsoft Access
Re: JSP Web Development by sbucareer(f): 11:07pm On Mar 21, 2007

Go to control panel and click on Administrative Tools, select and click Data Sources (ODBC) You will see all the picture below, follow the red arrows between them

Re: JSP Web Development by sbucareer(f): 11:16pm On Mar 21, 2007

Create a datasource and put it in a directory. Remember the datasource name as this is how we will refer to it in our java file. I have given this datasource name as pizza.

Datasource is the actuall file system name of your database records.

Re: JSP Web Development by sbucareer(f): 11:47pm On Mar 21, 2007

Let see a little javabean program that connects to our datasource


import java.sql.*;

public class PizzaBean {
private Connection con;
private Statement stmt;
private Resultset rs;

String datasourceName = "pizza";
String dbURL = "jdbc:odbc:" + dataSourceName;

public PizzaBean(){
   try{
//load the database driver and instantiate it
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"wink.newInstance();
       con =  DriverManager.getConnection( dbURL, "", ""wink;
   }catch(Exception e){
          e.getMessage();
  }//End constructor

public Connection getConnection(){
   return con;
}//End get|Connection

public void createTable (String tableName){
 
     String query = "Create Table"+ tableName + "(name varchar(15)"+
                                                                      "address varchar(20),"+
                                                                      "purchaseType varchar(6),"+
                                                                      "margherita varchar(5),"+
                                                                      "hawaiian varchar(5),"+
                                                                      "pepperoni varchar(5));";
     try{
               if (getConnection == null)
                       this.getConnection;

               stmt = con.createStatement()
               rs = stmt.executeQuery(query);
     }catch(Exception e){
          e.getMessage();
     }

  //You can add more methods to suit you

}//End of PizzaBean class
         
Re: JSP Web Development by sbucareer(f): 8:45am On Mar 22, 2007

l think the Jdbc connection is literally straight forward. If you find any part difficult let us know.

Forget tomcat at the moment, open your ready to program and create tables, update, insert and delete records.
Re: JSP Web Development by Taysay(m): 9:58am On Mar 22, 2007
@Sbucareer,
Good day, Pls I tried to correct the errors in the servlet, yet I have an error which I just cant seem to figure out, from my command prompt the error is on line 55. pls can you give me a lead. This is the code at that point. Sorry I am asking to be spoon fed. Never mind I will catch up in no time.


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.ServletResponse;
import javax.servlet.*;
import java.io.*;
import java.util.*;

public class interestRate extends HttpServlet{



private double loanAmount = 6400;
private double interestRate = 40.9; //Too expensive
private int numYears = 4;

public void doGet(
HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException{
response.setContentType("text/html"wink;

PrintWriter out = response.getWriter();

out.println("<html>"wink;
out.println("<head>"wink;
out.println("<title>Loan calculation</title>"wink;
out.println("</head>"wink;
out.println("<body>"wink;
out.println("<h2>Loan Calculation</h2>"wink;

out.println("Loan Amount:"wink;
out.println("<br/>"wink;
out.println("Interest Rate:"wink;
out.println("<br/>"wink;

out.println("*****************************"wink;
out.println("<br/>"wink;
out.println("Number of years:"wink;
out.println("<br/>"wink;
out.println("Total interest:"wink;
calculateInterest(loanAmount,interestRate,numYears);
out.println("<br/>"wink;
out.println("******************************"wink;
out.println("<br/>"wink;
out.println("Monthly repayments:"wink;
loanRepayments(loanAmount,interestRate,numYears);
out.println("<br/>"wink;

//Change the value of years
numYears++;

out.println("*****************************"wink;
out.println("<br/>"wink;
out.println("Number of years:"wink;
out.println("<br/>"wink;
out.println("Total interest:"wink;

double calculateInterest(double loanAmount,double interestRate,int numYears){
return numYears * interestRate * loanAmount / 100;

out.println("<br/>"wink;

out.println("******************************"wink;
out.println("<br/>"wink;
out.println("Monthly repayments:"wink;

String loanRepayments(double loanAmount,
double interestRate,
int numYears){
perc2 = new DecimalFormat("$#,##0.00;{$#,##0.00}"wink;
return perc2.format(( calculateInterest(loanAmount,interestRate,numYears) + loan ) / (numYears *12));
out.println("</body>"wink;
out.println("</html>"wink;


}//End doGet

public void doPost(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException{
doGet(request, response);
}//End doPost

}//End Process
}
}


Good bless Sbucareer!
Re: JSP Web Development by sbucareer(f): 10:29am On Mar 22, 2007

Taysay, for a start the servlet class would not compile. Why? You have not yet included the methods. i.e.

1. calculateInterest ()
2. loanRepayment()

Remember that your servlet is a java class file. Every methods(function as they call it in c/c++) used MUST be declared and coded if possible. Therefore your code would look like this



import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.ServletResponse;
import javax.servlet.*;
import java.io.*;
import java.util.*;

public class InterestRate extends HttpServlet{



  private double loanAmount = 6400;
  private double interestRate = 40.9; //Too expensive
  private int numYears = 4;
  private DecimalFormat perc2;

    public void doGet( HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException{
      response.setContentType("text/html"wink;

       PrintWriter out = response.getWriter();

    out.println("<html>"wink;
    out.println("<head>"wink;
    out.println("<title>Loan calculation</title>"wink;
    out.println("</head>"wink;
    out.println("<body>"wink;
    out.println("<h2>Loan Calculation</h2>"wink;

    out.println("Loan Amount:"wink;
     out.println("<br/>"wink;
      out.println("Interest Rate:"wink;
      out.println("<br/>"wink;

     out.println("*****************************"wink;
     out.println("<br/>"wink;
     out.println("Number of years:"wink;
     out.println("<br/>"wink;
     out.println("Total interest:"wink;
     out.println(calculateInterest(loanAmount,interestRate,numYears));
     out.println("<br/>"wink;
     out.println("******************************"wink;
     out.println("<br/>"wink;
     out.println("Monthly repayments:"wink;
     out.println( loanRepayments(loanAmount,interestRate,numYears));
     out.println("<br/>"wink;

    //Change the value of years
     numYears++;

    out.println("*****************************"wink;
    out.println("<br/>"wink;
    out.println("Number of years:"wink;
    out.println("<br/>"wink;
     out.println("Total interest:"wink;

    out.println("<br/>"wink;

    out.println("******************************"wink;
    out.println("<br/>"wink;
    out.println("Monthly repayments:"wink;

     out.println("</body>"wink;
     out.println("</html>"wink;


}//End doGet

   public void doPost(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException{
      doGet(request, response);
   }//End doPost


  public double calculateInterest(double loanAmount, double interestRate, int numYears ){
       
          return numYears * interestRate * loanAmount / 100;
  }//End calculateInterest

  public String loanRepayments( double loanAmount, double interestRate, int numYears){
          perc2 = new DecimalFormat("$#,##0.00;{$#,##0.00}"wink;
          return perc2.format(( calculateInterest(loanAmount,interestRate,numYears) + loan )  / (numYears *12));
  }//End loanRepayments
}//End InterestRate class


And your class name MUST start with Capital letter in java world.

Re: JSP Web Development by sbucareer(f): 12:10pm On Mar 22, 2007

Save this file as compile.bat under your C:\ drive

UPDATE your PATH to include your development directory my is (C:\Miscellaneous\nairaland) i.e.

PATH=;C:\Miscellaneous\nairaland


REM set this compile.bat to your PATH i.e. PATH=;C:\Miscellaneous\nairaland


cd\
REM productionDirectory. My is C:\Miscellaneous\nairaland

cd C:\Miscellaneous\nairaland\

javac -g *.java

mov *.class c:\program files\Apache Software Foundation\Tomcat 6.0\webapps\ROOT\WEB-INF\classes


Type compile from your command line interface that will compile your java file from your production directory and put the class file to the container %CATALINA_HOME%\webapps\ROOT\WEB-INF\classes

If all goes well you can access your servlet from http://localhost/servlet/InterestRate

I have issues with my own. The error message was in my catalina.log, it say

22-Mar-2007 10:28:03 org.apache.catalina.startup.HostConfig deployDirectory
SEVERE: Error deploying web application directory docs
java.lang.SecurityException: Servlet of class org.apache.catalina.servlets.InvokerServlet is privileged and cannot be loaded by this web application
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1134)

I think the problem is that the new version of Tomcat would not allow you to run servlet under the ROOT context because of security issues. I will find a way to sort that and I will post the solutions.
Re: JSP Web Development by sbucareer(f): 12:13pm On Mar 22, 2007

Meanwhile, Taysay the error free servlet of InterestRate.java is given bellow.

import java.text.*;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class InterestRate extends HttpServlet{



   private double loanAmount = 6400;
   private double interestRate = 40.9; //Too expensive
   private int numYears = 4;
   private DecimalFormat perc2;

    public void doGet( HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException{
       response.setContentType("text/html"wink;

        ServletOutputStream out = response.getOutputStream();
/*
        PrintWriter out = response.getWriter(); You can use either one. Both are the same Just that the ServletOutputStream is included in the Servlet API */



    out.println("<html>"wink;
    out.println("<head>"wink;
    out.println("<title>Loan calculation</title>"wink;
    out.println("</head>"wink;
    out.println("<body>"wink;
    out.println("<h2>Loan Calculation</h2>"wink;

    out.println("Loan Amount:"wink;
     out.println("<br/>"wink;
      out.println("Interest Rate:"wink;
      out.println("<br/>"wink;

     out.println("*****************************"wink;
     out.println("<br/>"wink;
     out.println("Number of years:"wink;
     out.println("<br/>"wink;
     out.println("Total interest:"wink;
     out.println(calculateInterest(loanAmount,interestRate,numYears));
     out.println("<br/>"wink;
     out.println("******************************"wink;
     out.println("<br/>"wink;
     out.println("Monthly repayments:"wink;
     out.println( loanRepayments(loanAmount,interestRate,numYears));
     out.println("<br/>"wink;

    //Change the value of years
     numYears++;

    out.println("*****************************"wink;
    out.println("<br/>"wink;
    out.println("Number of years:"wink;
    out.println("<br/>"wink;
     out.println("Total interest:"wink;

    out.println("<br/>"wink;

    out.println("******************************"wink;
    out.println("<br/>"wink;
    out.println("Monthly repayments:"wink;

     out.println("</body>"wink;
     out.println("</html>"wink;
     out.close();


}//End doGet

   public void doPost(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException{
       doGet(request, response);
   }//End doPost


   public double calculateInterest(double loanAmount, double interestRate, int numYears ){
         
           return numYears * interestRate * loanAmount / 100;
   }//End calculateInterest

   public String loanRepayments( double loanAmount, double interestRate, int numYears){
           perc2 = new DecimalFormat("$#,##0.00;{$#,##0.00}"wink;
           return perc2.format(( calculateInterest(loanAmount,interestRate,numYears) + loanAmount )  / (numYears *12));
   }//End loanRepayments
}//End InterestRate class
Re: JSP Web Development by sbucareer(f): 2:26pm On Mar 22, 2007

I have searched the net about InvokerServlet is privileged in my catalina.log in error log directory because I could not access my InterestRate.java class.

It happens that Tomcat 6.0 have made changes to the Invoker servlet. You need to explicitly define servlet in the web.xml to be able to access it. What I still do not understand is how to make a servlet a privileged file. Here is the forum I got some ideas from.

Sorry, people I do not want to introduce you to web.xml yet but the version of Tomcat we are using would not allow use to do servlet invoker. So comment out in your container web.xml under the this directory C:\Program Files\Apache Software Foundation\Tomcat 6.0\conf  the mappings to Invokers

If you are using Tomcat 4.1, which is the last tomcat I used before this trail, you would be able to use the invoker.

Also see invoker is evil

In my opinion, they should drop invoker altogether

Re: JSP Web Development by sbucareer(f): 2:55pm On Mar 22, 2007

Let learn how to bloody code web.xml since apache said that invoker is evil

Normally web application is a single entity collection of jsp, html, servlet, beans, classes, jpeg etc. Let say we want to create a school application. We will create a folder under webapps called school under school web app we will have the following folder and file

1. WEB-INF\classes (Mandatory)
2. WEB-INF\lib (Optional)
3. WEB-INF\web.xml (Mandatory if your are going to use servlet under Tomcat 6.0)
4. images (Optional)


ROOT is the default web application  apache added into all Tomcat. There is no reason why we should continue using it. Infact we can change our webapps directory to another cluster or filepath by modifying server.xml in the conf directory

<Host name="localhost"  appBase="webapps"
           unpackWARs="true" autoDeploy="true"
           xmlValidation="false" xmlNamespaceAware="false">

Infact you can create a directory called interestRate and make sure it has all these directories and file(s)

1. WEB-INF\classes (Mandatory)
2. WEB-INF\lib (Optional)
3. WEB-INF\web.xml (Mandatory if your are going to use servlet under Tomcat 6.0)
4. images (Optional)

How you access it from the URL is http://localhost/engine.exe if you are using port 8080 etc. http://localhost:8080/engine.exe. If your listing directory is not switched off from the server.xml, you will see all the directories in your web app apart from WEB-INF. You can NEVER see that folder Tomcat's security measures that is why your web.xml file is there and you classes directory and lib (library) directory.

Now this is how we code web.xml.

Re: JSP Web Development by sbucareer(f): 3:14pm On Mar 22, 2007


The following web.xml should be saved in ROOT\WEB-INF\web.xml and make sure your InterestRate.class is in ROOT\WEB-INF\class\InterestRate.class
and access the servlet like this

http://87.194.38.96/engine.exe


<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"wink; you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"
    version="2.5">

  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Interest rate calculation web application
  </description>

     <servlet>
    <servlet-name>interest</servlet-name>
    <servlet-class>InterestRate</servlet-class>
     </servlet>

     <servlet-mapping>
  <servlet-name>interest</servlet-name>
        <url-pattern>/engine.exe</url-pattern>
     </servlet-mapping>


     <error-page>
<error-code>500</error-code>
<location>/errorPage.jsp</location>
     </error-page>

</web-app>
Re: JSP Web Development by Bossman(m): 12:09am On Mar 23, 2007
Excellent tutorial! Keep up the good work sbucareer.

I just want to mention that, if you are referencing any javabean objects from your JSP, tomcat 5.0 and above requires that thay be in a package. If not the JSP compiler will not be able to find them.
Re: JSP Web Development by sbucareer(f): 2:30am On Mar 23, 2007

Bossman, thanks. I wanted to introduce them to bean and servlet and how to compile a simple java. Package in Java is a hierarchal place holder java components should go according to individual.

Le say I am developing a timesheet web application for and organization called ubuntuBiz, I would try and organize my classes into logical location. So let say we have a web application folder under %CATALINA_HOME%\webapps called ubuntuBiz, then I will have the following folders

1. ubuntuBiz\WEB-INF\web.xml
2. ubuntuBiz\WEB-INF\classes\com\ubuntuBiz\beans
3. ubuntuBiz\WEB-INF\classes\com\ubuntuBiz\servlets
4.ubuntuBiz\WEB-INF\classes\com\ubuntuBiz\dao
5. ubuntuBiz\WEB-INF\classes\com\ubuntuBiz\utilities
6. ubuntuBiz\WEB-INF\lib
7. ubuntuBiz\jsp
8. ubuntuBiz\images
9. ubuntuBiz\index.jsp

Now, if was was to code a servlet class, I will put it under the ubuntuBiz\WEB-INF\classes\com\ubuntuBiz\servlets directory. If I was to create bean class, I will put it under the ubuntuBiz\WEB-INF\classes\com\ubuntuBiz\beans directory and etc.

Also, in the class of servlet class definition I MUST dd this signature


package com.ubuntuBiz.beans; //For beans classes

import java.sql.*;
public class UbuntubBizBean{

,
}//End


Finally, in the application web.xml I will do this

<web-app>
,
,

<servlet-class>com.ubuntuBiz.bean.UbuntuBean</servlet-class>

,
,
</web-app>
Re: JSP Web Development by Taysay(m): 12:27pm On Mar 23, 2007
Good day,
Pls I tried running this file from my netbeans, and encountered the following problems
It had errors on lines 45
<td><b><jsp:getProperty name="pizza" property="hawaiia" v/></b></td></tr>
on correcting this line, another error came up on line 28
<td><b> <jsp:getProperty name="pizza" property="purchaseType" value="0"/> </b></td></tr>
The compiler was complaining that the getProperty has invalid attribute: value
After all attempts the I could only get the green light when I removed the value attribute entirely from lines 28 and 32
Yet on attempting to run the file it failed giving me this error
init:
deps-module-jar:
deps-ear-jar:
deps-jar:
library-inclusion-in-archive:
library-inclusion-in-manifest:
compile:
compile-jsps:
org.apache.jasper.JasperException: The value for the useBean class attribute com.nairaland.beans.Pizza is invalid.
C:/J2EEProjects/sbucareer/build/web/pizzas.jsp(10,3)
C:\J2EEProjects\sbucareer\nbproject\build-impl.xml:353: Java returned: 1
BUILD FAILED (total time: 3 seconds)

Funny enough attempting to compile and run my file from the command prompt via Textpad, my file ran displaying this image in my dreamweaver viewer and my internet Explorer



Over to you sir, Pls what is it that I am not doing right?

Re: JSP Web Development by sbucareer(f): 12:38pm On Mar 23, 2007

Hmm,  You are leaving me again to solve your problems for you? The beauty of programming is NOT in writing the code but in DEBUGGING. Have you ever wondered why programmers or developers stay late at work? And, why software project is always late?

I can see your problem, but I am not telling. Try and debug it and look for answers. Use the debugger option in your javac, use the option -g i.e.

c:\>javac -g InterestRate.java


You look at this line yourself very carefully and tell me if you see a problem?

<td><b><jsp:getProperty name="pizza" property="hawaiia" v/></b></td></tr>

Re: JSP Web Development by Taysay(m): 1:48pm On Mar 27, 2007
@Sbucareer,
Sorry you havent heard from me 'cos I have being really sick, so I will resume classes next week. thanx
Re: JSP Web Development by teeewai(m): 6:12pm On Apr 01, 2007
@sbucareer
let's face it u've been a real source of help 2 people like me. keep it up man. av been 4llowing u8r tutorial on jsp, i tried to install netbeans 5.0 which has a bundled apache tomcat server inside and i couldn't get through with configuring the server properties i choose port 8084 cos i already have IIs runnin on port 80. the tomcat server keeps requesting for password for manager role which i don't know. plz help me out. 10x
Re: JSP Web Development by Bossman(m): 8:23pm On Apr 01, 2007
Did you try blank? I think that's the default. Under tomcatDir/conf/tomcat-user.xml what password do you have associated with the manager role? Exactly what are you trying to doi that it keeps asking for the admin PW?

teeewai:

the tomcat server keeps requesting for password for manager role which i don't know. plz help me out. 10x
Re: JSP Web Development by Taysay(m): 5:16pm On Apr 05, 2007
@SBUCAREER,
good day My dear LECTURER! so sorry I didnt mean to discourage you, I feel really ill, I had though that I will be back in class this week but some how, I had to travel to accra with my sweetheart so pls I will be back in class in another 10days. I really appreciate you. you r such a blessing, meanwhile I have seen my mistake from the line of code you sent, unfortunately I am not equiped to run codes here, i really miss running codes though. thanx so very much for your understanding.

(1) (2) (Reply)

ASP.NET MVC [C#] Php Laravel - Training From Scratch-apply now / (revealed) So Mark Zuckerberg Is Not That Good At Coding/programming! / Is It Difficult To Build A Forum Like Nairaland?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 117
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.