Monday, 27 April 2009

1-SIMPLE AND COMPLETE DATA SOURCE EXAMPLE

This is an implementation of the logic given on the MySQL site. The difference is: My solution is simple and complete. A step by step explanation follows:

I used Jdev 11g, and a small DB table on MySQL, I deployed my application to Tomcat due to some problems with WebLOGIC.

The first step is to test whether you can run servlets directly clicking on them and selecting the run command:
For this, you have to set the web.xml first.

FILE: web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app version="2.4" uri="http://java.sun.com/xml/ns/j2ee" >

<display-name>
Test ARS data source
</display-name>

<servlet>
<servlet-name>RequestDisplay</servlet-name>
<servlet-class>dsweb.RequestDisplay</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RequestDisplay</servlet-name>
<url-pattern>/RequestDisplay</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>DStest</servlet-name>
<servlet-class>dsweb.DStest</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DStest</servlet-name>
<url-pattern>/DStest</url-pattern>
</servlet-mapping>

<resource-ref>
<res-ref-name>jdbc/MySQLDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

<welcome-file-list>
<welcome-file>Welcome.html</welcome-file>
</welcome-file-list>
</web-app>

Here, I use RequestDisplay as a test servlet to check whether I can run a servlet.

FILE: RequestDisplay.java
package dsweb;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RequestDisplay extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {

response.setContentType("text/html");
java.io.PrintWriter out = response.getWriter();
out.println("<html><head><title>Request Attribute</title></head><body>");
out.println("<h2>Request attribute values</h2>");

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


} //end doGet

}



( next )