classes:general:dbsamples:jsp_oracle
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
classes:general:dbsamples:jsp_oracle [2017/01/14 19:50] – [Connecting using a Bean] localadmin | classes:general:dbsamples:jsp_oracle [2017/01/14 19:52] (current) – [The Class (Bean)] localadmin | ||
---|---|---|---|
Line 72: | Line 72: | ||
< | < | ||
package beans; | package beans; | ||
- | |||
import java.io.*; | import java.io.*; | ||
Line 122: | Line 121: | ||
Once compiled, this class needs to be placed in the folder: / | Once compiled, this class needs to be placed in the folder: / | ||
+ | |||
+ | ==== The JSP page ==== | ||
+ | |||
+ | The JSP page will be placed in the public_html directory, and can be reached through the URL http:// | ||
+ | |||
+ | To use the database functions defined in your bean, you need to use a special JSP directive. | ||
+ | |||
+ | You can import packages using the syntax: | ||
+ | < | ||
+ | <%@page import=" | ||
+ | </ | ||
+ | This imports java.util.* | ||
+ | |||
+ | To import your bean, use the syntax: | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | This defines an object called ' | ||
+ | |||
+ | This is similar to the java: | ||
+ | < | ||
+ | DBCon dbcon = new DBCon(); | ||
+ | </ | ||
+ | |||
+ | in that it makes a new object for code the use. The difference is that jsp:useBean is used for JSP pages to load Beans. | ||
+ | |||
+ | Here is a small JSP page that loads the DBCon bean and calls the function getRecords(). Note that we do not specify ANY database connection information here, that's taken care of in the DBCon bean. | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | |||
+ | <%@page import=" | ||
+ | < | ||
+ | |||
+ | <% | ||
+ | // Get the first item of each record by calling a function of the DBCon class | ||
+ | ArrayList records = dbcon.getRecords(); | ||
+ | |||
+ | // Go through each record and print | ||
+ | for(int i = 0; i < records.size(); | ||
+ | { | ||
+ | // Print out each item in the ' | ||
+ | out.println(" | ||
+ | out.println("< | ||
+ | } | ||
+ | |||
+ | %> | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
classes/general/dbsamples/jsp_oracle.1484445020.txt.gz · Last modified: 2017/01/14 19:50 by localadmin