UK Sales: 0800 035 6364 | sales@2020media.com | We'll Call You

What is JSP?

 

Java Server Pages (JSP) is a technology that lets you mix regular, static HTML with dynamically-generated HTML. Many Web pages that are built by CGI programs are mostly static, with the dynamic part limited to a few small locations. But most CGI variations, including servlets, make you generate the entire page via your program, even though most of it is always the same. JSP lets you create the two parts separately. Here's an example:

 



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD><TITLE>Welcome to Our Store</TITLE></HEAD>
<BODY>
<H1>Welcome to Our Store</H1>
<SMALL>Welcome,
<!-- User name is "New User" for first-time visitors -->
<% out.println(Utils.getUserNameFromCookie(request)); %> To access your account settings, click
<A href="/Account-Settings.html">here.</A></SMALL>
<P>

Regular HTML for all the rest of the on-line store's Web page.

</BODY></HTML>

 

What are the Advantages of JSP?

 

vs. Active Server Pages (ASP)

 

ASP is a similar technology from Microsoft. The advantages of JSP are twofold. First, the dynamic part is written in Java, not Visual Basic or other MS-specific language, so it is more powerful and easier to use. Second, it is portable to other operating systems and non-Microsoft Web servers.

 

vs. Pure Servlets

 

JSP doesn't give you anything that you couldn't in principle do with a servlet. But it is more convenient to write (and to modify!) regular HTML than to have a zillion println statements that generate the HTML. Plus, by separating the look from the content you can put different people on different tasks: your Web page design experts can build the HTML, leaving places for your servlet programmers to insert the dynamic content.

 

vs. Server-Side Includes (SSI)

 

SSI is a widely-supported technology for including externally-defined pieces into a static Web page. JSP is better because it lets you use servlets instead of a separate program to generate that dynamic part. Besides, SSI is really only intended for simple inclusions, not for "real" programs that use form data, make database connections, and the like.

 

vs. JavaScript

 

JavaScript can generate HTML dynamically on the client. This is a useful capability, but only handles situations where the dynamic information is based on the client's environment. With the exception of cookies, HTTP and form submission data is not available to JavaScript. And, since it runs on the client, JavaScript can't access server-side resources like databases, catalogs, pricing information, and the like.

 

vs. Static HTML

 

Regular HTML, of course, cannot contain dynamic information. JSP is so easy and convenient that it is quite feasible to augment HTML pages that only benefit marginally by the insertion of small amounts of dynamic data. Previously, the cost of using dynamic data would preclude its use in all but the most valuable instances.

 

Finding out more

 

Definitive book is

 

Core Servlets and JavaServer Pages by Marty Hall ISBN 0-13-089340-4

 

As usual the Sun site is also very useful.

 

Servlets

 

Overview of Java Servlets

 

Servlets provide the ability to generate pages dynamically using the Servlet extensions to the Java language. Servlets have the following advantages over other common server extension mechanisms:

 

  • They are faster than CGI scripts because they use a different process model.
  • They use a standard API that is supported by many Web servers.
  • They have all of the advantages of the Java language, including ease of development and platform independence.
  • They can access the large set of APIs available for the Java platform.

 

We offer servers running JDK 1.2 and above with JServ as our standard platform for Servlets.

 

Useful Links

 

Servlets Servlet Tutorial Servlet API Tomcat Using Tomcat
Suns Servlet Home Page Useful information for writing Servlets Documentation is available for download Part of the Java Apache project Using your Java account with Servlets

 

 

 

JavaServer Pages (JSP)

 

Pages that use JSP are stored on the server as HTML with extra syntax to access Java programs embedded within them. This means that you can use all the usual tools to generate the look and feel of the pages, and embed the active contents within them easily. Other features allow easy connection between HTML Forms and Bean objects for processing.

 

Useful Links

 

JSP JSP API Using JSP Jspin
Sun JSP Page. Latest API and information The specification can be downloaded from the SUN site from here Hints on using JSP on 2020Media Servers Resource for scripts and tutorials

 

What are the differences between Access and SQL Server?

This is a question we're often asked, so here's a quick summary of the main additional features you'll find in SQL Server 2000/2005:

AutoNumbers are Int fields with an Index
Indexes can be applied at any time, not just on a new table
InStr and Mid become CharIndex and SubStr
You can't refer to a date within # anymore, SQL Server uses '
Lists for IN() can't end in a , anymore
Data isn't written immediately, it's queued
SQL Server can return the Index field within the SQL
You can set-up Stored Procedures to do complex SQL commands and just call them within SQL
You can by-pass the record locking to improve speed
You can alter a table definition while it's still in use

Access also supports a lower number of concurrent connections and does not scale as well as SQL 

2020Media offers Access on Windows Server 2000/3 and Microsoft SQL Server 2000/2005. If you are currently using Access and want to upgrade to SQL2000, SQL2005 , contact us.

A jar file is simply a collection of classes that are packaged together for easy of distribution. A war file is pretty much the same thing for web applications. You put jar files into the classpath of applications in order to use whats in them. Similarly you deploy a war file into the webapps directory of a java servelt container in order to deploy it as a web app.

 

The basic jar syntax is;

jar -[options] jar-file input-file(s)

example
jar -cvf jam.jar *.*

The above options are defined as;

- c – create
- v – verbose
- f – file

The name of the jar file is jam.jar and the files used to create this jar file are basically everthing in the current directory (*.*).

You can also extract a jar file using the option “x” (extract)

example
jar -xvf jam.jar *.*

Finally to view the contents of a jar file use the “t” option.

example
jar -tvf jam.jar

A  war file is pretty created in exactly the same way. All you need to do is create a file with a  .war extension rather than a .jar extension.

example
jar -cvf jam.war *.*

Java & MySQL

 

The full documentation and information about MySQL can be found at http://www.mysql.com/documentation/index.html, Alternatively, MySQL by Paul DuBois is a good reference (ISBN 0-7357-0921-1)

 

Test your MySQL Servlet Account is working

 

At this point it is assumed that the basic servlets are working. To see how to test this go to Using Servlets

 

To test that the connection to MySQL is working, open up a web browser and go to

 

http:// webserver /mountpoint / testDB2020

 

where

 

webserver is the name for your web server
mountpoint is the name of the mount points for servlets.

 

Both of these are in the account detail letter.

 

This should bring up a page looking like:

 

2020Media Database Servlet Connection Working

 

You have connected successfully

 

If this does not happen, then contact support.

 

Connecting to MySQL

 

The following code fragments show the supported method of connecting to MySQL.

 



import java.sql.*;

import java.io.*;

import java.util.*;



import javax.servlet.*;

import javax.servlet.http.*;



......



public static final String DB_URL = "jdbc\:mySQL\://db_servername/db_database";

public static final String DB_USERNAME = "db_username";

public static final String DB_PASSWORD  = "db_password";

public static final String DB_DRIVER = "org.gjt.mm.mysql.Driver";



......



public void init() throws ServletException

{

try

{

Class.forName(DB_DRIVER);

}

catch(java.lang.ClassNotFoundException e)

{

......

}

try

{

con = DriverManager.getConnection(DB_URL,

DB_USERNAME, DB_PASSWORD);

}

catch(SQLException ex)

{

...........

}

where
db_username , db_password, db_servername and db_database are detailed in your account information.

We urge you to use code as close to this as possible, as it aids our debugging of any problems.

 

The source for the test page is available in the 'src' directory.

 

Accessing the Database

 

To access the database for creating tables and monitoring status, you may need to run an MySQL client. This can be done either from the command line or from your own computer.

 

Using the command line

 

There is a command line client which can be accessed by typing

 

mysql -u db_username -p -h db_hostname

 

This allows you to access the database from the command line. It is not very user friendly, but allows you to execute SQL commands directly.

 

You will then be prompted for your Database password. It should then return a prompt. You can then type in commands - followed by the word ';' .

 

Example

 

    show databases;



 

This should return a list of databases and some information about them. More details on using MySQL can be found here.

 

Page 1 of 2

2020Media is a leading provider of small business Wi-Fi hotspots. If you want to offer free Wi-Fi to your customers or users, our service could be exactly what you are looking for. Our Hotspots are managed in the cloud, ultra-reliable and give you loads of information about behaviour patterns of your users. Read More   Read more...
2020Media introduces Moodle Hosting - UK servers and UK Moodle experts setup your site ready to use. Read more...
Special Offer for Longer Registration Periods Register or renew a .com, .net or .org domain name for 5 years we'll include 1 year free*. Read more...
2020Media is now offering zero-click installation of the popular TYPO3 content management system. Read more...

Our blog is regularly updated with news, tips and industry opinion.

Clients

  • AggieWestons
  • baker-and-mckenzie
  • arts-council-england
  • Big Finish
  • barratt-developments-logo
  • City-of-Lincoln-council-logo
  • brora-logo
  • DenisMacShane
  • Construction-Industry-Council
  • colchester