Build a Web site using JSP
Author:Eve Cole
Update Time:2009-07-02 17:12:37
JSP is a technology launched by Sun Microsystems in June 1999. It is a Web development technology based on JavaServlet and the entire Java system. This technology can be used to build advanced, secure and cross-platform dynamic websites.
JSP is very similar to ASP. Both provide the ability to mix some kind of program code in HTML code and have the program code interpreted and executed by the language engine. In an ASP or JSP environment, HTML code is mainly responsible for describing the display style of information, while program code is used to describe processing logic. The programming language under ASP is a scripting language such as VBScript, while JSP uses Java.
TRS and its JavaBeans
The TRS system is the first Chinese full-text retrieval system in the world that adopts "parallel computing" algorithm. Its full-text retrieval engine can provide performance that relational databases do not have, and can be used in conjunction with relational databases; because TRS can establish full-text text content Index, providing efficient full-text search capabilities. Therefore, using TRS can greatly improve the query speed of the website.
TRS JavaBeans is developed based on Java component technology - JavaBeans and has good cross-platform features. This article will introduce the process of building a Web using JSP, TRS and JavaBeans.
TRS JavaBeans configuration steps
Take WebLogic5.1.0 under NT as an example.
1.Install WebLogic5.1.0
2. Modify startWebLogic.cmd
Change "set PRE_CLASSPATH=" to "set PRE_CLASSPATH=% full path of %TRSBean.jar%; full path of %TRSDemo.jar%".
For example: If TRSBean.jar is located in the C:TRSJavaBeanslib directory, change this statement to:
set PRE_CLASSPATH=C:TRSJavaBeanslibTRSBean.jar
3. Modify weblogic.properties
Remove the # sign in front of the statement: #weblogic.httpd.register.servlets=weblogic.servlet.ServletServlet.
Remove the "#" sign before the following statements:
# weblogic.httpd.register.*.jsp=
# weblogic.servlet.JSPServlet
#weblogic.httpd.initArgs.*.jsp=
# pageCheckSeconds=1,
# compileCommand=C:/java/bin/javac.exe,
# workingDir=D:/weblogic/myserver/classfiles,
#verbose=true
Then change "compileCommand=C:/java/bin/javac.exe," to "compileCommand=JAVA_PATH/bin/javac.exe,", where JAVA_PATH is the installation root directory of the actual JDK used.
4.Install DEMO
Copy the entire DEMO directory of the TRSJavaBeans installation package to the D:/weblogic/myserver/public_html directory.
After completing the above configuration, we can enter the design and development stage.
Development example
Suppose the database is: "news.Investment News", and the fields are "title", "content", "date" and "number" (unique field).
Take displaying the detailed content of a specific record as an example. As for paging display, full-text search and BBS, etc., due to space limitations, we will not go into details. Interested users can try it themselves. Actual operation results can be found on Yixin.net (www.exin.net) or Beijing Investment Platform (www.bjinvest.gov.cn).
The jsp program is as follows:
<HTML>
<HEAD>
<TITLE>News</TITLE>
<link REL="stylesheet" href="mycss.css"TYPE="text/css">
<META content="text/html; charset=GB2312"http-equiv=Content-Type>
<%@ page import="com.eprobiti.TRS.*"%>
<%@ page import="java.util.*"%>
<jsp:useBean id="TRSConn" scope ="session" class="com.eprobiti.TRS.TRSConnection"/>
<jsp:useBean id="TRSRS"scope ="page" class="com.eprobiti.TRS.TRSResultSet"/>
</HEAD>
<BODY>
<%
String item_id = request.getParameter("id");
//The parameter id is passed from the URL or the form hidden field of the previous file
String dbname,ip,port,username,password;
dbname = "news.Beijing News";
//TRS database name
ip="202.123.166.99"; //TRS server IP
port="8888";//TRS server port
username="yourname";
//You can search the user name of "news.Beijing News"
password="yourpassword";
//The password corresponding to the username
String filter = "number="+item_id;
//Define search conditions
try {
if (TRSConn.connect(ip,port,username,password)){ }
//Establish a connection with the TRS server
else {
out.println("Connection connection failed!n");
}
TRSRS = TRSConn.executeSelect(dbname,s1,"","", null, 0, 0, false);
//Execute query operation and generate record set
} catch(TRSException TRSe) {
out.println("ResultSet connection failed!n");
}
try {
TRSRS.moveFirst();
//Record positioning
%>
<p>
<center>
<table width=80%>
<tr align=center>
<td><%=TRSRS.getString("Title")%>
</td>
</tr>
<tr align=center>
<td><%=TRSRS.getString("Date")%>
</td>
</tr>
<tr>
<td><%=TRSRS.getString("content")%>
</td>
</tr>
</table>
</center>
<p>
<%
TRSRS.close();
} catch(TRSException TRSe) {}
%>
</body>
</html>