Oracle 5.0 Reference Manual page 2135

Table of Contents

Advertisement

writer.println("<p>Population: "+rs.getString("Population")+"</p>");
}
}
writer.println("</body></html>");
writer.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
public void doGet(HttpServletRequest req, HttpServletResponse resp){
try {
resp.setContentType("text/html");
PrintWriter writer = resp.getWriter();
writer.println("<html><body>");
writer.println("<p>Hello from servlet doGet()</p>");
writer.println("</body></html>");
writer.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
In the preceding code a basic
The code to establish the connection with the database is as shown in the previous example,
Section 20.3.14.1, "A Simple JSP Application with Glassfish, Connector/J and
conveniently located in the servlet
in the destroy method. The main functionality of the servlet is located in the
user enters nto the input form a country name that can be located in the database, the population of the
country is returned. The code is invoked using a POST action associated with the input form. The form
is defined in the file index.html:
<html>
<head><title>HelloWebServlet</title></head>
<body>
<h1>HelloWebServlet</h1>
<p>Please enter country name:</p>
<form action="HelloWebServlet" method="POST">
<input type="text" name="country_name" length="50" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
The XML files
web.xml
Section 20.3.14.1, "A Simple JSP Application with Glassfish, Connector/J and
changes are required.
Whe compiling the Java source code, you will need to specify the path to the file javaee.jar. On
Windows, this can be done as follows:
shell> javac -classpath c:\glassfishv3\glassfish\lib\javaee.jar HelloWebServlet.java
Once the code is correctly located within its directory structure, and compiled, the application can be
deployed in Glassfish. This is done in exactly the same way as described in the preceding section,
Section 20.3.14.1, "A Simple JSP Application with Glassfish, Connector/J and
Once deployed the application can be launched from within the Glassfish Administration Console.
Enter a country name such as "England", and the application will return "Country does not exist!". Enter
"France", and the application will return a population of 59225700.
Using Connector/J with GlassFish
method is implemented, but is not used in the example.
doGet()
method. The corresponding freeing of resources is located
init()
and
are as for the example in the preceding section,
sun-web.xml
2115
MySQL", and is most
method. If the
doPost()
MySQL", no additional
MySQL".

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents