JSP simple Add, query function code _jsp programming

Source: Internet
Author: User
Tags odbc stmt mail account

The example of this article describes the JSP simple Add, query function. Share to everyone for your reference. Specifically as follows:

JSP Technology:

public class ISOtoGb2312
{public
static String convert (String str)
{
try
{
byte<> Bytesstr=str.getbytes ("iso-8859-1");
return new String (Bytesstr, "gb2312"); 
}
catch (Exception ex)
{return
str;
}
}
}

<%@ page contenttype= "text/html; charset=gb2312 "%>  
<%@ page contenttype= "text/html; charset=gb2312 "%> <%@ page import =" java.sql.* "%> <%@ page language =" java "%> <%@ page import =" Test . ISOtoGb2312 "%>  

Jsp1:

<%@ page contenttype= "text/html; charset=gb2312 "%> <%@ page import=" com.borland.internetbeans.*,com.borland.dx.dataset.*, com.borland.dx.sql.dataset.* "%> <%@ taglib uri="/internetbeans.tld "prefix=" IX "%> <%@ taglib uri=" http://
Java.sun.com/jstl/sql "prefix=" SQL "%>  

Jsp1bean.java

Package test;
/*AAAAAAA
bbbbbbb
ccccccccc*/
/**
* <p>title: </p>
* <p>description: </p >
* <p>copyright:copyright (c) 2004</p>
* <p>company: </p>
* @author not Attributable
* @version 1.0 * * Public
class Jsp1bean {
private String sample = "Start value";
Access Sample Property Public
String Getsample () {return
sample;
}
Access Sample Property public
void Setsample (String newvalue) {
if (newvalue!=null) {
sample = NewValue ;
}
}
}

JSP2:

<%@ page contenttype= "text/html; charset=gb2312 "%> <%@ page import= java.sql.*"%> <%@ page language= "java"%> <HTML> <HEAD> &L T title> Sequential Access data </TITLE> </HEAD> <BODY> <CENTER> <font SIZE = 5 COLOR = blue> order to obtain data </ font> </CENTER> <BR> <HR> <BR> <CENTER> <% class.forname (" Sun.jdbc.odbc.JdbcOdbcDriver "); Load driver category Connection con = drivermanager.getconnection ("jdbc:odbc:zjyds1"); Establish a database link Statement stmt = con.createstatement (); Establishing statement object ResultSet RS; Establish resultset (Result set) Object rs = Stmt.executequery ("SELECT * from Tab01"); Execute SQL statements%> <table bgcolor=pink> <tr bgcolor=silver> <TD><B> School Number </B></TD>< td><b> name </B></TD><TD><B> sex </B></TD><TD><B> age </b
></TD><TD><B> address </B></TD> </TR> <%//using the while loop to list the records in the datasheet while (Rs.next ()) {%> <tr BGCOLOR=WHite> <td><b><%= rs.getstring ("id")%></b></td> <td><b><%= Rs.getstring ("name")%></b></td> <td><b><%= rs.getstring ("Sex")%></B></ td> <td><b><%= rs.getstring ("Age")%></b></td> <td><b><%= Rs.getstring ("addr")%></b></td> </TR> <%} rs.close (); Closes the ResultSet object Stmt.close (); Closes the Statement object Con.close ();

 Close Connection object%> </TABLE> </CENTER> </BODY> </HTML>

JSP3:

<%@ page contenttype= "text/html; charset=gb2312 "%>
 
 

JSP4:

<%@ page contenttype= "text/html; charset=gb2312 "%>
 
 

JSP6:

<%@ page contenttype= "text/html; charset=gb2312 "%>
 
 

JSP7:

<%@ page contenttype= "text/html; charset=gb2312 "%>
 
 

JSP8:

<%@ page contenttype= "text/html; charset=gb2312 "%>
 
 

Input.html

<HTML>
<HEAD>
<TITLE> web guide </TITLE>
</HEAD>
<BODY>
< center>
<font SIZE = 5 COLOR = blue> web guide </FONT>
</CENTER>
<BR>
<HR>
<BR>
<form action= "sendredirect.jsp" Method=post name=form1>
<P> Name: <input Name=inputname ></P>
<p>e-mail: <input name=inpute_mail ></P>
<input name= Submit Type=submit value= >
</FORM>
</BODY>
 
 

SENDREDIRECT.JSP:

<%@ page contenttype= "text/html; charset=gb2312 "%>
<%@ page language=" java "%>
<%
String Name = Request.getparameter (" InputName ");
String E_Mail = Request.getparameter ("Inpute_mail");
if (Name.equals ("") | | E_mail.equals (""))//check whether the name or E_Mail completes
the data entry Response.sendredirect ("sendredirect.html"); If the data input is not completed, it will
guide the sendredirect.html%>
<HTML>
<HEAD>
<TITLE> Web page </title >
</HEAD>
<BODY>
<CENTER>
<font SIZE = 5 COLOR = blue> Web page boot </font >
</CENTER>
<BR>
<HR>
<BR>
<P> Your name is:
<%= name %>
</P>
<p>e-mail account number:
<%= e_mail%>
</P>
<p><a href= ".. /jsp1.jsp "> Return </a></p>
</BODY>
</HTML>

Sendredirect.html:

<HTML>
<HEAD>
<TITLE> web guide </TITLE>
</HEAD>
<BODY>
< center>
<font SIZE = 5 COLOR = blue> web guide </FONT>
</CENTER>
<BR>
<HR>
<BR>
<form action= "sendredirect.jsp" Method=post name=form1> <font size=5 color=red
>
The information you entered is incomplete, please re-enter!
</font>
<br>
<P> name: <input name=inputname ></P>
<P> E-mail: <input name=inpute_mail ></P>
<input name=submit type=submit value= send out >
</form >
</BODY>
</HTML>

I hope this article will help you with the JSP program design.

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.