JSP code (add, query)

Source: Internet
Author: User
Tags insert mail odbc reset stmt mail account
JS 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 "%>
<title>
Enter data
</title>
<body bgcolor= "#ffffff" >
Please enter the data:
<form method= "POST" action= "insert.jsp" >
<!--WebBot bot= "SaveResults" u-file= "Fpweb:///_private/form_results.txt"
s-format= "Text/csv" s-label-fields= "TRUE"-->
<p> </p>

<p> </p>
<p>
<font size= "5" color= "#0000FF" ><b> School No.:
</b></font><input type= "text" name= "id" size= ">
<font size= "5" color= "#0000FF" ><b> gender </b></font><font size= "5" color= "#0000FF" ><b ":"
</b></font><input type= "text" name= "Sex" size= "></p>"
<p>
<font size= "5" color= "#000080" ><b> name:
</b></font><input type= "text" name= "name" size= ">
<font size= "5" color= "#0000FF" ><b> Ages: </b></font><input type= "text" name= "Age" size= "24" ></p>

<p>
<font size= "5" color= "#000080" ><b> Address:
</b></font><input type= "text" name= "addr" size= "> </p>"

<p> </p>

<p>
<input type= "Submit" value= "submitted" name= "B1" style= "FONT-SIZE:14PT; Font-weight:bold ">
<input type= "Reset" value= "all Rewrite" name= "B2" style= "FONT-SIZE:14PT; Font-weight:bold ">
</p>
</form>


</body>
---------------------------------------------------------------------
<%@ page contenttype= "text/html; charset=gb2312 "%>
<%@ page import = "java.sql.*"%>
<%@ page language = "java"%>
<%@ page import = "Test." ISOtoGb2312 "%>
<title>
Add data
</title>
<body bgcolor= "#ffffff" >
Receive data and add to the database.
<%
Class.forName ("Sun.jdbc.odbc.JdbcOdbcDriver"); Load driver category
Connection con = drivermanager.getconnection ("jdbc:odbc:zjyds1"); Establish a database link
Statement stmt = con.createstatement (resultset.type_scroll_insensitive,
RESULTSET.CONCUR_READ_ONLY);
String strSQL;
strSQL = "INSERT into tab02 (ID, name, sex," +
"Age, Addr" Values ("+
Isotogb2312.convert (Request.getparameter ("id")) + "," +
Isotogb2312.convert (Request.getparameter ("name")) + "," +
Isotogb2312.convert (Request.getparameter ("Sex")) + "," +
Isotogb2312.convert (Request.getparameter ("Age")) + "," +
Isotogb2312.convert (Request.getparameter ("addr")) + ")";
Stmt.executeupdate (strSQL);
ResultSet rs; To create a resultset (result set) object
rs = Stmt.executequery ("SELECT * from TAB02"); Execute SQL statement
%>
<CENTER>
<table bgcolor=pink>
<tr bgcolor=silver>
<TD><B> number </B></TD><TD><B> name </B></TD><TD><B> sex </ B></td><td><b> Age </B></TD><TD><B> Address </B></TD>
</TR>
<%
Use a while loop to list the records in a 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 (); Close ResultSet Object
Stmt.close (); Close Statement Object
Con.close (); Close Connection Object
%>
</TABLE>
</CENTER>
</body>
-----------------------------------------------------------------------------------






Message person: Liu Chen message time: 2004-5-17 18:30:38

Message content:
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"%>
<title>
Jsp1
</title>
<jsp:usebean id= "Jsp1beanid" scope= session "class=" test. Jsp1bean "/>
<jsp:setproperty name= "Jsp1beanid" property= "*"/>
<body bgcolor= "#ff00ff" >
JBuilder generated JSP
<br>
This is the first time to use JSP technology!!! ----2004/3/1--Software College of Nanchang University----
<br>
<br>
<form method= "POST" >
<br>enter new value: <input name= "Sample" ><br>
<br>
<input type= "Submit" name= "submit" value= "Submit" >
<input type= "reset" value= "reset" >
<br>
Value of Bean property is: <jsp:getproperty name= "Jsp1beanid" property= "Sample"/>
</form>
</body>
-----------------------------------------------------------------------------------------------------------
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>
<TITLE> Order Access Data </TITLE>
</HEAD>
<BODY>
<CENTER>
<font SIZE = 5 COLOR = blue> order get 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 (); Create a statement object
ResultSet rs; To create a resultset (result set) object
rs = Stmt.executequery ("SELECT * from Tab01"); Execute SQL statement
%>
<table bgcolor=pink>
<tr bgcolor=silver>
<TD><B> number </B></TD><TD><B> name </B></TD><TD><B> sex </ B></td><td><b> Age </B></TD><TD><B> Address </B></TD>
</TR>
<%
Use a while loop to list the records in a 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 (); Close ResultSet Object
Stmt.close (); Close Statement Object
Con.close (); Close Connection Object
%>
</TABLE>
</CENTER>
</BODY>
</HTML>
-------------------------------------------------------------------------------------------
JSP3:
<%@ page contenttype= "text/html; charset=gb2312 "%>
<title>
Jsp3
</title>
<jsp:usebean id= "Jsp3beanid" scope= session "class=" test. Jsp3bean "/>
<jsp:setproperty name= "Jsp3beanid" property= "*"/>
<body bgcolor= "#ffffc0" >
JBuilder generated JSP
<form method= "POST" >
<br>enter new value: <input name= "Sample" ><br>
<br><br>
<input type= "Submit" name= "submit" value= "Submit" >
<input type= "reset" value= "reset" >
<br>
Value of Bean property is: <jsp:getproperty name= "Jsp3beanid" property= "Sample"/>
</form>
</body>
-----------------------------------------------------------------------------------------------
JSP4:
<%@ page contenttype= "text/html; charset=gb2312 "%>
<title>
Login
</title>
<body bgcolor= "#ffffc0" >
<form method= "POST" action= "jsp6.jsp" >
<p align= "center" >
User name: <input type= "text" name= "username" size= "></p>"
<p align= "center" >
Password: <input type= "password" name= "password" size= "></p>"
<p align= "center" >
<input type= "Radio" value= "Manage" checked name= "select" >
Management
<input type= "Radio" name= "select" value= "statistic" > Statistics </p>
<p align= "center" ><input type= "submit" value= "Log In" name= "Login" >
<input type= "reset" value= "rewrite" name= "reset" ></p>
</form>
</body>
----------------------------------------------------------------------------------------------------------
JSP6:
<%@ page contenttype= "text/html; charset=gb2312 "%>
<title>
Receive data
</title>
<body bgcolor= "#ffffff" >
<%
String User,pwd,choice;

User=request.getparameter ("username");
Pwd=request.getparameter ("password");
Choice=request.getparameter ("select");

if (Choice.equals ("manage")) {
User select Manage.
%>
<jsp:forward page= "jsp7.jsp" >
<jsp:param name= "username" value= "<%=user%>"/>
<jsp:param name= "Password" value= "<%=pwd%>"/>
</jsp:forward>
<%
}else{
User Select statistic
%>
<jsp:forward page= "jsp8.jsp" >
<jsp:param name= "username" value= "<%=user%>"/>
<jsp:param name= "Password" value= "<%=pwd%>"/>
</jsp:forward>
<%
}
%>

</body>
-----------------------------------------------------------------------------------------------
JSP7:
<%@ page contenttype= "text/html; charset=gb2312 "%>
<title>
Jsp7
</title>
<body bgcolor= "#ffffff" >
This is the admin page!!!
<br>
<%
String user,pwd;
User=request.getparameter ("username");
Pwd=request.getparameter ("password");
%>
Username is: <%=user%><br>
Password is: <%=pwd%><br>

</body>
---------------------------------------------------------------------------------------------
JSP8:
<%@ page contenttype= "text/html; charset=gb2312 "%>
<title>
Jsp8
</title>
<body bgcolor= "#ffffff" >
This is the statistics page!!!
<br>
<%
String user,pwd;
User=request.getparameter ("username");
User=new String (Request.getparameter ("username"). GetBytes ("Iso8859_1"));
Pwd=request.getparameter ("password");
%>
Username is: <%=user%><br>
Password is: <%=pwd%><br>

</body>
----------------------------------------------------------------------------------------------------
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= send out >
</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 name or E_Mail completes data entry
Response.sendredirect ("sendredirect.html"); If the data input is not completed, the page will be directed to sendredirect.html
%>
<HTML>
<HEAD>
<TITLE> Web Guide </TITLE>
</HEAD>
<BODY>
<CENTER>
<font SIZE = 5 COLOR = blue> web Guide </FONT>
</CENTER>
<BR>
<HR>
<BR>
<P> Your name is:
<%= Name%>
</P>
<p>e-mail account number is:
<%= 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>


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.