Java environment

xiaoxiao2021-03-06  44

JSP is a referusion of JavaServer Pages, which is a technology integrating HTML and Java programs on a web page. I think using JSP writing programs more challenging than ASP, PHP and other languages, and learn knowledge because it involves object-oriented Java languages. To use good JSP, you have to have a certain understanding of Java. In addition, it is also required to skilled various development tools, like Dreamweaver, Photoshop, JBuilder, etc. Workers must be good, and must first make a tool. Before running the JSP program, you must do some preparations. First there must be a web server, Apache or IIS can; secondly have a compiler that executes a Java program; there is another engine that supports JSP, there are many engines available, such as Tomcat, WebLogic, Resin Wait. The message board program describes the message board program can run smoothly on the author's machine, the details are as follows: Operating system: Windows 2000 Server Java Compile: JDK1.3 Web Server: Apache1.13.2 Tomcat3.1 engine database: Access 2000 Apache The configuration after Tomcat is installed is a bit challenging. The following is my installation process: 1). Install JDK1.3 a). Double-click the J2SDK1_3_0-win.exe file, install it to the C: /JDK1.3 directory; b). Update The following environment variables, add C: /jdk1.3/lib/tools.jar; c: /jdk1.3/lib/dt.jar; C: / myclasses. Update: Right click on My Computer - Properties - Advanced - Environment Variables; C). Relonize your computer. 2). Install apache1.13.2 a). Double-click the apache_1_3_12_win32.exe file, install it under the C: / Apache directory; b). Modify C: /Apache/conf/httpd.conf: i) .port: Set Apache The port number used when Web Server runtime, I change it into the port 8080, enter http: // ip: 8080 on the browser, you can access the Apache Web Server server; II) .servername: I set ServerName to 202.38 .126.134 (This is my machine IP address); III). After installation, there are many Apache Web Server menu groups in the "Start-Program" menu group, running the Install Apache as a service, such Start - Setting - Control Panel - Services, there is more services called Apache, you can use it to start or stop Apache service; iv). Open "Start - Setting - Control Panel - Serving", choose Apache, press "Start" Start the Apache service.

c). Enter http: // ip: 8080 in IE (IP is the IP address of the machine you use), is Apache run? 3). Install Tomcat3.1 a). Use Winzip to extract Tomcat.zip into a directory, finally make C: / Tomcat; b). Open the c: /apache/conf/httpd.conf file, in this file Finally, add this sentence: include c: /tomcat/conf/tomcat.conf; c). Modify Tomcat running port number, note that Tomcat has a separate HTTP server, it must use a port that has not been used No. I use port: 80, modified in c: /tomcat/conf/server.xml; d). Plus set tomcat_home = c: / tomcat set java_home = c: /jdk1.3 plus C: / Tomcat / bin In /tomcat.bat file, the modified file is as follows: ... Rem guess tomcat_home if it is not present set tomcat_home = c: / tomcat set java_home = c: /jdk1.3 if not "% Tomcat_Home%" == "" Goto Gothome There is also ... e). Double click C: /TOMCAT /STARTUP.BAT to boot Tomcat; F). Enter http: // ip / if you can see Tomcat on your browser Version 3.1 This page means that the Tomcat is successful.

It is almost the same, and finally creates a directory in the Tomcat directory, which is used to store the program, the specific situation is as follows: c: / tomcat / fox - store .html and .jsp file C: / tomcat / fox / Images - Store image file C: / tomcat / fox / global - Store Database C: / Tomcat / Fox / Web-INF / CLASSES - Store Java Class File In order to make the JSP program in this directory can run smoothly, Need to add a few lines of code in the c: /tomcat/conf/server.xml file: After the completed server.xml file looks like this: ... < Context path = "/ test" DOCBASE = "WebApps / test" debug = "0" reloadable = "true"> below ... Now write a program called Test.jsp, save C: / Tomcat/fox/test.jsp <% java.util.date Date = new java.util.date ();%> Hello! The time is now <% out.println (Date %> Type http://ip/fox/test.jsp in IE, if you can see the current time, congratulations: You can start writing a message board program. I. Create a database 1). Open Access2000, create a new database, I name this database foxdb.mdb, exist C: /Tomcat/fox/global/foxdb.mdb.

Next, create a table in Eagle.mdb, named FoxTable, five fields in the table, all text format: "URL" is used to record the IP of the message. As for the length of each field, I set "message" as 200, and the other four are 20. 2). Specify the ODBC data source, which is named foxdb, pointing to C: / Tomcat/fox/global/foxdb.mdb.

II. Write the user's message interface foxnote.html, exist in c: /tomcat/fox/foxnote.html:


Name:
Mailbox:
3. Writing FoxNoteInsert.jsp, write the user's message into the database table: <% @ page import = "java.sql. *, myutil, java.util. *"%> <% connection conne = null; String username = MyUtil.gb2312ToUnicode (request.getParameter ( "username")); String email = MyUtil.gb2312ToUnicode (request.getParameter ( "email")); String doc = MyUtil.gb2312ToUnicode (request.getParameter ( "doc ")); String url = request.getRemoteAddr (); try {class.forname (" sun.jdbc.odbc.jdbcodbcdriver); con = drivermanager.getConnection ("JDBC: ODBC: FoxDB", "," ") String str = "INSERT INTO FOXTABLE VALUES ?,?,?,?); "PrepaaredStatement pstmt = con.preparestatement (STR); pstmt.setstring (1, username); pstmt.setstring (2, email); pstmt.setstring (3, doc);

PSTMT.SetString (4, URL); pstmt.executeUpdate (); pstmt.close (); con.close ();} catch (e.getMessage ());}%> This program There are some places to be explained, just in which JavaBean: myutil.class is used. MyUTil's role is the conversion between strings. The string of the JSP is indicated by the Unicode code, but the form of the message board interface is represented in GB2312. Therefore, write the user's message into the database also requires the conversion between the code. If you don't transform, write your message directly to the database table, you will have garbled. The following is the original code of MyUt, exists in c: /tomcat/fox/web-inf/classes/myutil.java, and the compiled MyUtil.class file also exists.

import java.io. *; public class MyUtil {public static String gb2312ToUnicode (String s) {try {return new String (s.getBytes ( "ISO8859_1"), "gb2312");} catch (UnsupportedEncodingException uee) {return s; }} public static String unicodeTogb2312 (String s) {try {return new String (s.getBytes ( "gb2312"), "ISO8859_1");} catch (UnsupportedEncodingException uee) {return s;.}}} four write foxnoteview.jsp Used to browse the message already in the database table, exist in c: /tomcat/fox/foxnoteView.jsp, code as follows: <% @ Page ContentType = "text / html; charset = GB2312" Langguage = "Java" import = "java.sql. *"%> <% connection con = null; try {class.forname ("sun.jdbc.odbc.jdbcodbcodbdriver"); con = DriverManager.getConnection ("JDBC: ODBC: Foxdb "," "," "); statement statement (); resultset = statement.executeQuery (" select * from foxtable ");%>

author Published 转载请注明原文地址:https://www.9cbs.com/read-79823.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.036, SQL: 9