Home arrow Java & J2EE arrow Page 7 - Slapping Together A JSP Development Environment

Making The Grade - Java

Deploying a JSP development environment on your workstation cantest even the strongest of wills, since it requires the peacefulco-existence and cooperation of a number of complex software packages. Thistutorial guides you through the process of getting Apache, JServ and Tomcatconfigured, alerts you to some of the problems you're likely to encounter,and briefly discusses Tomcat contexts and JSP-mySQL connections. Coversboth Windows and Linux.

TABLE OF CONTENTS:
  1. Slapping Together A JSP Development Environment
  2. Essential Software
  3. One Tomcat, Standing Alone
  4. Connecting The Dots
  5. Same Story, Different OS
  6. Putting It In Context
  7. Making The Grade
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 4
March 05, 2001

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
If you plan to use JSP to communicate with a database using a JDBC connection, there are a couple of additional things you need to do.

First, get yourself a copy of the mm.mySQL module from http://www.worldserver.com/mm.mysql/ or http://mmmysql.sourceforge.net/ - this is required to communicate with the database. Extract the file "mysql.jar" from the archive, and place it in your JDK's LIB/ folder.

Next, add the location of this file to the CLASSPATH variable. On Windows, use

C:\>SET CLASSPATH=%CLASSPATH%;C:\JDK\LIB\MYSQL.JAR

and on Linux, use

$ CLASSPATH=$CLASSPATH:/usr/local/jdk/lib/mysql.jar; export CLASSPATH

Pop open your favourite text editor and create the following JSP file:

<html> <head> </head> <%@ page language="java" import="java.sql.*" %> <body> <% Class.forName("org.gjt.mm.mysql.Driver"); //assume database "test", user "root", password "" // change this as per your requirements Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password= "); Statement stmt = myConn.createStatement(); // assume you have a "grades" table with // grades is various subjects and student names // change this as per your requirements String query = "select * from grades where literature > 90"; ResultSet myResultSet = stmt.executeQuery(query); if (myResultSet != null) { while (myResultSet.next()) { // specify the field name String name = myResultSet.getString("name"); %> <%= name %> <br> <% } } stmt.close(); myConn.close(); %> </body> </html>

This is a simple JSP file to connect to a database, run a query and return the results. Remember to modify the database name, user details and query in the example above before proceeding.

Finally, start up Tomcat, Apache and mySQL. Point your browser to the file you just created - say, http://localhost/examples/jsp/query.jsp and JSP should display the results of your query.

And that's it. You now know how to set up a JSP development environment with minimum fuss and effort. Now get out there and show those kids how the pros do it!

 
 
>>> More Java & J2EE Articles          >>> More By icarus, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

JAVA & J2EE ARTICLES

- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: