About JSP environment configuration and bean settings

Source: Internet
Author: User
Tags getmessage variables stmt xmlns port number tomcat oracle database
JS I am also a novice, just the two days in the face of the problem written out, to other and I the same traveler to provide reference, because is a beginner, to many concepts, nouns unavoidably have many deficiencies, please point out and give excuse me.

Keywords: JSP TOMCAT configuration Environment Bean Oracle database connection

First, the required software: jdk1.5.0_03 Download Address: http://192.18.97.107/ecom/ecomticketservlet/begin714bec085bf81689f1cf58a75f4a7a9a/- 2147483648/856515651/1/615302/615146/856515651/2ts+/westcoastfsend/jdk-1.5.0_03-oth-jpr/jdk-1.5.0_03-oth-jpr:2 /jdk-1_5_0_03-windows-i586-p.exe Installation path defaults to: C:\Program files\java\jdk1.5.0_03

jdk1.5.0_03 Document Download Address: http://192.18.97.47/ECom/EComTicketServlet/BEGIN4485078F3F07F886D616C10A357249D3/-2147483648 /856519743/1/531806/531794/856519743/2ts+/westcoastfsend/jdk-1.5.0-doc-oth-jpr/jdk-1.5.0-doc-oth-jpr:1/jdk-1_5 _0-doc.zip Installation path defaults to: C:\Program files\java\jre1.5.0_03

jakarta-tomcat-5.0.1 Download Address: Slightly Install the path is: C:\Tomcat 5.0

Oracle9i Enterprise Version (Chinese) installation path is default: D:\oracle installation method can refer to other information, also can be installed by its default way.

Second, the operating environment: Windows Server

Iii. Development tools: JCreator 2.5 (writing, debugging Java) Dreamweaver mx (design page) plsql Developer (Oracle database)

Iv. configuration process: After installing the JDK and Tomcat, set the JDK system environment variables (note the system environment variables and a user environment variable):
Java_home=c:\program Files\java\jdk1.5.0_03classpath=files\java\jdk1.5.0_03\jre\lib\rt.jar;.; Path=%java_home%\bin If Oracle is installed, PATH will become: d:\oracle\ora90\bin;d:\oracle\ora90\apache\perl\5.00503\bin\ mswin32-x86; C:\Program Files\oracle\jre\1.1.8\bin;%java_home%\bin;

To set the TOMCAT environment variable: TOMCAT_HOME=C:\TOMCAT 5.0

Restart your computer.

Test Tomcat: Enter in Browser: http://127.0.0.1: Port number/ If you see the above picture, that Tomcat is running normally.

Set Tomcat virtual directory: Open the Server.xml under C:\Tomcat 5.0\conf, find

Restart Tomcat after the settings have been completed and after the Tomcat is closed again.

In the browser input: http://127.0.0.1: Port number/manager/html, (required to enter the password when you install the user name and password set, the user name by default: admin), can also be entered: http://127.0.0.1: port number , and then select the Tomcat Manager under administration on the right.

The following screen will appear: and you can see the virtual directory you just set up.

To set Oracle database driver: Open: D:\oracle\ora90\jdbc\lib, copy classes12.jar file to: C:\Program files\java\jdk1.5.0_03\jre\lib\ Ext another copy to: C:\Tomcat 5.0\common\classes

Then restart Tomcat, and if not, it is recommended that you restart the computer.

Test your own JSP file with a database connection (file name: oracle_b.jsp): <%@ page contenttype= "text/html;charset=gb2312"%> <%@ page Import= "java.sql.*"%><?xml version= "1.0" encoding= "gb2312"? ><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<body><%        String oracledbdriver= "Oracle.jdbc.driver.OracleDriver";        String dburl= "Jdbc:oracle:thin:@127.0.0.1:1521:erpdata";       //1521 is the default port for Oracle databases, erpdata the SID that is installed for Oracle, which is the database name        String userid= "Scott";       string userpwd= "Tiger";               Connection conn=null;       Statement   stmt=null;       resultset  rs=null;        try       {       Class.forName (OracleDBDriver );      }       catch (ClassNotFoundException ex)        {               SystEm.out.println ("Class.forName:" +ex);        }    conn= Drivermanager.getconnection (dburl,userid,userpwd);     //stmt=conn.prepareStatement ( resultset.type_scroll_sensitive,resultset.concur_read_only);    stmt=conn.createStatement ();     String sql= "select * from EMP";    rs = stmt.executequery (sql);    & nbsp;       out.print ("<table border>");          out.print ("<tr>");            out.print (" <th width=100> "+" UserID ");               out.print ("<th width=50>" + "UserName");          out.print (" <tr> "); try   {        while (Rs.next ())          {          out.print ("<tr>");             int N=rs.getint (1);                out.print ("<td>" +n+ "</td>");                string e=rs.getstring (2);                out.print ("<td>" +e+ "</td>");           out.print ("</tr>");        }    }       catch (SQLException ex)        {               System.err.println ("Conndb.main: "+ex.getmessage ());      }

Out.print ("</table>");        Rs.close (); %> </body>

You can copy the above content to the oracle_b.jsp file and save it in your virtual directory folder. Enter in the browser: http://127.0.0.1/web/oracle_B.jsp is visible to the following:

The bean is used in the JSP. In the virtual directory (such as: D\TNF) under the establishment of the Web-inf\classes folder, namely: D:\tnf\WEB-INF\classes with JCreator or other tools in writing the following:/** * <p> database connection Private Package </p > * <p>copyright: Shepherd's Copyright (c) 2005</p> * <p>company: Shepherd </p> * @by: Shepherd 18272024 Websuper @126.com * @version 1.0 * *

Package DB;

Import java.sql.*;

Public class conndb{       String oracledbdriver= "Oracle.jdbc.driver.OracleDriver ";       String dburl=" Jdbc:oracle:thin:@127.0.0.1:1521:erpdata ";               String userid= "Scott";        String userpwd= "Tiger";              Connection conn=null;       statement  stmt=null;        resultset  rs=null;      

Load Database driver ... public conndb () {try {class.forname (oracledbdriver); catch (ClassNotFoundException e) {System.err.println ("conndb ():" +e.getmess              Age ()); }}

Insert data public void Executeinsert (String sql) {try {conn=drivermanager.getconnection Dburl,use           RID,USERPWD);           Stmt=conn.createstatement ();           Stmt.executeupdate (SQL);           Stmt.close ();       Conn.close ();       The catch (SQLException ex) {System.err.println ("Conndb.executeupdate:" +ex.getmessage ()); }}

Query data public ResultSet executequery (String sql) {       try        {              conn= Drivermanager.getconnection (DBURL,USERID,USERPWD);               stmt=conn.createstatement ();              //stmt=conn.createstatement (resultset.type_scroll_sensitive,resultset.concur_read_only);               rs=stmt.executequery (SQL);       }       catch (SQLException exc)         {              System.err.println ("Conndb.executequery:" +exc.getmessage ());      }        return RS;}

/**public static void Main (String args[]) {       conndb conn=new conndb ();   & nbsp;    String sql= "select * from EMP";       ResultSet rs= Conn.executequery (SQL);              try        {              while ( Rs.next ())               {                      System.out.print (Rs.getint (1) + "  ");                      System.out.print (rs.getstring (2) + "  ");                       SysteM.out.print (rs.getstring (3) + "  ");                      System.out.print (Rs.getint (4) + "  ");                       System.out.println (Rs.getdate (5));              }      }       catch (SQLException ex)        {               System.err.println ("Conndb.main:" +ex.getmessage ());      }}**/

}

The file Conndb.java is then saved in d:\tnf\WEB-INF\classes. It is then compiled into a class byte code file.

Note: The package followed by the DB, compiled into class bytes will generate a new folder, and package immediately followed (such as DB) the same, build do not change its name, preferably with the package after the name. I've been having this problem for days.

The oracle.jsp file is then set up as follows: <%@ page contenttype= "text/html;charset=gb2312"%> <%@ page import= "java.sql.*"%> <jsp:usebean id= "conn" class= DB. Conndb "scope=" page/><?xml version= "1.0" encoding= "gb2312"? ><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<body><%       /**string oracledbdriver= "Oracle.jdbc.driver.OracleDriver" ;       String dburl= "Jdbc:oracle:thin:@192.168.1.15:1521:erpdata";               String userid= "Scott";        String userpwd= "Tiger";              Connection conn=null;       statement  stmt=null;        resultset  rs=null;              Class.forName (oracledbdriver);    conn=drivermanager.getconnection (DBUrl,UserID,UserPWD);      //stmt=conn.preparestatement (Resultset.type_scroll_sensitive,resultset.concur_read_ only);    stmt=conn.createstatement (); **/    string sql= "select * from EMP";   &nbsP ResultSet rs = conn.executequery (sql);            out.print ("< Table border> ");          out.print (" <tr> ");             out.print ("<th width=100>" + "UserID");                out.print ("<th width=50>" + "UserName");           out.print ("<tr>");         while (Rs.next ())         {           out.print ("<tr>");             String n=rs.getstring (1);                out.print ("<td>" +n+ "</td>");                string E=rs.getstring (2);                Out.print ("<td>" +e+ "</td>");          out.print ("</tr> ");        }

Out.print ("</table>");        Rs.close ();        String sql= "INSERT into systemusertable values (" + "'" +allrown+ "', ' operator ', ' 1234 ', ' 02 ', 0)";        Rs=stmt.executeupdate (SQL); Rs.close;%> </body>

Shepherd May 16, 2005 in Shenzhen



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.