Many JSP programmers aim to develop websites. The prvalue of a website is called PageRank, which is an integral part of google's ranking algorithm, the level ranges from 1 to 10, and the Level 10 is the full score. The higher the PR value, the more important the page is in the search ranking. That is to say, when other conditions are the same, websites with a high PR value have priority in the ranking of google search results.
So how to create a JSP message board to improve the PR value of your website and enhance interaction? Let's get started!
I. JSP message board: Create a database
1) Open Access2000 and create a new database. I name this database as foxdb. mdb, and C: \ tomcat \ fox \ global \ foxdb. mdb exists. Next, create a table in eagle. mdb named foxtable. The table has five fields in the text format:
The URL is used to record the IP address of the message recipient. As for the length of each field, I set "message" to 200, and the other four to 20.
2) Specify the ODBC data source named foxdb, pointing to C: \ tomcat \ fox \ global \ foxdb. mdb.
Ii. JSP message board: Compile the user's message interface
Foxnote.html, stored in C: \ tomcat \ fox \ foxnote.html:
- <Html>
- <Body>
- <FormMethod="Post" Action="Foxnoteinsert. jsp">
- <Br> Name:
- <InputName=Username Size=15 value= "">
- <Br> Email:
- <InputName=Email Size=15 value= "">
- <Br> message:
- <Br>
- <TextareaName=Doc Rows="5" Cols="40">
- </Textarea>
- <Br>
- <InputType=Submit Value="Submit">
- <InputType=Reset Value="Refill">
- </Form>
- </Bocy>
- </Html>
-
In IE, type http: // ip/fox/foxnote.html to check whether the normal ip address is the ip address of your machine)
Iii. JSP message board: Compile foxnoteinsert. jsp
Write users' messages into the database table:
- ﹤body bgcolor="#FFFFFF"﹥
- ﹤%@ page import="java.sql.*,MyUtil,java.util.*"%﹥
- ﹤%
- Connection con=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("jdbcdbc:foxdb","","");
- String str="insert into foxtable values(?,?,?,?);";
- PreparedStatement 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(Exception e) {
- out.println(e.getMessage());
- }
- %﹥
-
In this program, a JavaBean: MyUtil. class is used.
MyUtil is used to convert strings. Note that the JSP string is represented by Unicode code, while the form on the message board interface is represented by gb2312 code. Therefore, writing users' messages into the database also requires code conversion. If messages are directly written to the database table without conversion, garbled characters are generated. The following is the original code of MyUtil, stored in C: \ tomcat \ fox \ WEB-INF \ classes \ MyUtil. java, the compiled MyUtil. class file is also stored here.
- 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;
- }
- }
- }
-
4. JSP message board: Compile foxnoteview. jsp
Used to browse existing messages in the database table and store them in C: \ tomcat \ fox \ foxnoteview. jsp. The Code is as follows:
- <Html>
- <Body>
- <%@ Page cLanguage="Java" Import="Java. SQL .*"%>
- <%
- ConnectionCon=Null;
- Try
- {
- Class. forName ("sun. jdbc. odbc. JdbcOdbcDriver ");
- Con=DriverManager. GetConnection ("jdbcdbc: foxdb ","","");
- StatementStatement=Con. CreateStatement ();
- ResultSetRs=Statement. ExecuteQuery ("select * from foxtable ");
-
- %>
- <TableBorder="1" Width="100%" Cellspacing="0" Cellpadding= "0"Align= "Center"Bordercolorlight="# CCCCFF" Bordercolordark="# FFFFFF">
- <TrBgcolor="# FFFFFF">
- <TdWidth="15%" Height="25" Align="Center"> <I> author </I> </td>
- <TdWidth="28%" Height="25" Align="Center">< I> posting time </I> </td>
- <TdWidth="22%" Height="25" Align="Center"> <I> Email </I> </td>
- <TdWidth="35%" Height="25" Align="Center"> <I> message content </I> </td>
- <%
- While (rs. next ()){
- Out. println ("<TR> <tdAlign=Center> <FontSize=2 color= #999999> "+ rs. getString (" author ") +" </TD> ");
- Out. println ("<TD> <fontSize=2 color= #999999> "+ rs. getString (" Email ") +" </font> </TD> ");
- Out. println ("<TD> <fontSize=2 color= #999999> "+ rs. getString (" message ") +" </font> </TD> ");
- Out. println ("<TD> <fontSize=2 color= #999999> "+ rs. getString (" URL ") +" </font> </TD> </TR> ");
- }
- Rs. close ();
- Con. close ();
- }
- Catch (Exception e)
- {
- Out. println (e. getMessage ());
- }
- %>
- </Table>
- </Body>
- </Html>
-
By now, the entire JSP message board program has been completed. The message board is relatively simple in database applications, but it can write a variety of applications and operate a variety of databases.
- Analysis of JSP Design Mode
- JSP tutorial basics-HTML form demonstration
- JSP tutorials-basic articles-simple homepage Creation
- Specific algorithms for implementing the tree structure of JSP forums
- JSP entry-level website environment setup steps