|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
你精通任何一门语言就最强大。现在来看,java的市场比C#大,C#容易入手,比较简单,java比较难jsJSP手艺:
----------------------------------------
publicclassISOtoGb2312
{
publicstaticStringconvert(Stringstr)
{
try
{
bytebytesStr=str.getBytes("ISO-8859-1");
returnnewString(bytesStr,"gb2312");
}
catch(Exceptionex)
{
returnstr;
}
}
}
-------------------------------------------------------------------
<%@pagecontentType="text/html;charset=GB2312"%>
<html>
<head>
<title>
输出数据
</title>
</head>
<bodybgcolor="#ffffff">
<h1>
请输出数据:
</h1>
<hr>
<formmethod="POST"action="insert.jsp">
<!--webbotbot="SaveResults"U-File="fpweb:///_private/form_results.txt"
S-Format="TEXT/CSV"S-Label-Fields="TRUE"-->
<p> </p>
<p> </p>
<p>
<fontsize="5"color="#0000FF"><b>学号:
</b></font><inputtype="text"name="id"size="25">
<fontsize="5"color="#0000FF"><b>性别</b></font><fontsize="5"color="#0000FF"><b>:
</b></font><inputtype="text"name="sex"size="24"></p>
<p>
<fontsize="5"color="#000080"><b>姓名:
</b></font><inputtype="text"name="name"size="25">
<fontsize="5"color="#0000FF"><b>年龄:</b></font><inputtype="text"name="age"size="24"></p>
<p>
<fontsize="5"color="#000080"><b>地址:
</b></font><inputtype="text"name="addr"size="84"></p>
<p></p>
<p>
<inputtype="submit"value="提交"name="B1"style="font-size:14pt;font-weight:bold">
<inputtype="reset"value="全体重写"name="B2"style="font-size:14pt;font-weight:bold">
</p>
</form>
</body>
</html>
---------------------------------------------------------------------
<%@pagecontentType="text/html;charset=GB2312"%>
<%@pageimport="java.sql.*"%>
<%@pagelanguage="java"%>
<%@pageimport="test.ISOtoGb2312"%>
<html>
<head>
<title>
增加数据
</title>
</head>
<bodybgcolor="#ffffff">
<h1>
吸收数据,增加到数据库.
</h1>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//载进驱动程序种别
Connectioncon=DriverManager.getConnection("jdbc:odbc:zjyds1");//创建数据库链接
Statementstmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
StringstrSQL;
strSQL="INSERTINTOtab02(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);
ResultSetrs;//创建ResultSet(了局集)对象
rs=stmt.executeQuery("SELECT*FROMtab02");//实行SQL语句
%>
<CENTER>
<TABLEbgcolor=pink>
<TRbgcolor=silver>
<TD><B>编号</B></TD><TD><B>姓名</B></TD><TD><B>性别</B></TD><TD><B>年龄</B></TD><TD><B>地址</B></TD>
</TR>
<%
//使用while轮回将数据表中的纪录列出
while(rs.next())
{
%>
<TRbgcolor=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();//封闭ResultSet对象
stmt.close();//封闭Statement对象
con.close();//封闭Connection对象
%>
</TABLE>
</CENTER>
<h3><ahref="jsp1.jsp">前往</a></h3>
</body>
</html>
-----------------------------------------------------------------------------------
留言人:刘晨留言工夫:2004-5-1718:30:38
留言内容:
jsp1:
<%@pagecontentType="text/html;charset=GB2312"%>
<%@pageimport="com.borland.internetbeans.*,com.borland.dx.dataset.*,com.borland.dx.sql.dataset.*"%>
<%@tagliburi="/internetbeans.tld"prefix="ix"%>
<%@tagliburi="http://java.sun.com/jstl/sql"prefix="sql"%>
<html>
<head>
<title>
jsp1
</title>
</head>
<jsp:useBeanid="jsp1BeanId"scope="session"class="test.Jsp1Bean"/>
<jsp:setPropertyname="jsp1BeanId"property="*"/>
<bodybgcolor="#ff00ff">
<h1>
JBuilderGeneratedJSP
<br>
<hr>
这是第一次利用JSP手艺!!!----2004/3/1--南昌年夜学软件学院----
</h1>
<h3><ahref="tmp/page_1.htm">另外一页</a></h3>
<br>
<h3><ahref="jsp2.jsp">下一页</a></h3>
<br>
<h3><ahref="DBBean.jsp">数据库</a></h3>
<formmethod="post">
<br>Enternewvalue:<inputname="sample"><br>
<br>
<inputtype="submit"name="Submit"value="Submit">
<inputtype="reset"value="Reset">
<br>
ValueofBeanpropertyis:<jsp:getPropertyname="jsp1BeanId"property="sample"/>
</form>
<h3><ahref="jsp4.jsp">登录</a></h3>
</body>
</html>
-----------------------------------------------------------------------------------------------------------
Jsp1Bean.java
packagetest;
/*aaaaaaa
bbbbbbb
ccccccccc*/
/**
*<p>Title:</p>
*<p>Description:</p>
*<p>Copyright:Copyright(c)2004</p>
*<p>Company:</p>
*@authornotattributable
*@version1.0
*/
publicclassJsp1Bean{
privateStringsample="Startvalue";
//Accesssampleproperty
publicStringgetSample(){
returnsample;
}
//Accesssampleproperty
publicvoidsetSample(StringnewValue){
if(newValue!=null){
sample=newValue;
}
}
}
----------------------------------------------------------------------------------------------------------
jsp2:
<%@pagecontentType="text/html;charset=GB2312"%>
<%@pageimport="java.sql.*"%>
<%@pagelanguage="java"%>
<HTML>
<HEAD>
<TITLE>按次获得数据</TITLE>
</HEAD>
<BODY>
<CENTER>
<FONTSIZE=5COLOR=blue>按次获得数据</FONT>
</CENTER>
<BR>
<HR>
<BR>
<CENTER>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//载进驱动程序种别
Connectioncon=DriverManager.getConnection("jdbc:odbc:zjyds1");//创建数据库链接
Statementstmt=con.createStatement();//创建Statement对象
ResultSetrs;//创建ResultSet(了局集)对象
rs=stmt.executeQuery("SELECT*FROMtab01");//实行SQL语句
%>
<TABLEbgcolor=pink>
<TRbgcolor=silver>
<TD><B>学号</B></TD><TD><B>姓名</B></TD><TD><B>性别</B></TD><TD><B>年龄</B></TD><TD><B>地址</B></TD>
</TR>
<%
//使用while轮回将数据表中的纪录列出
while(rs.next())
{
%>
<TRbgcolor=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();//封闭ResultSet对象
stmt.close();//封闭Statement对象
con.close();//封闭Connection对象
%>
</TABLE>
</CENTER>
</BODY>
</HTML>
-------------------------------------------------------------------------------------------
jsp3:
<%@pagecontentType="text/html;charset=GB2312"%>
<html>
<head>
<title>
jsp3
</title>
</head>
<jsp:useBeanid="jsp3BeanId"scope="session"class="test.Jsp3Bean"/>
<jsp:setPropertyname="jsp3BeanId"property="*"/>
<bodybgcolor="#ffffc0">
<h1>
JBuilderGeneratedJSP
</h1>
<formmethod="post">
<br>Enternewvalue:<inputname="sample"><br>
<br><br>
<inputtype="submit"name="Submit"value="Submit">
<inputtype="reset"value="Reset">
<br>
ValueofBeanpropertyis:<jsp:getPropertyname="jsp3BeanId"property="sample"/>
</form>
</body>
</html>
-----------------------------------------------------------------------------------------------
jsp4:
<%@pagecontentType="text/html;charset=GB2312"%>
<html>
<head>
<title>
登录
</title>
</head>
<bodybgcolor="#ffffc0">
<formmethod="POST"action="jsp6.jsp">
<palign="center">
用户名:<inputtype="text"name="username"size="20"></p>
<palign="center">
密码:<inputtype="password"name="password"size="20"></p>
<palign="center">
<inputtype="radio"value="manage"checkedname="select">
办理
<inputtype="radio"name="select"value="statistic">统计</p>
<palign="center"><inputtype="submit"value="登录"name="login">
<inputtype="reset"value="重写"name="reset"></p>
</form>
</body>
</html>
----------------------------------------------------------------------------------------------------------
jsp6:
<%@pagecontentType="text/html;charset=GB2312"%>
<html>
<head>
<title>
吸收数据
</title>
</head>
<bodybgcolor="#ffffff">
<%
Stringuser,pwd,choice;
user=request.getParameter("username");
pwd=request.getParameter("password");
choice=request.getParameter("select");
if(choice.equals("manage")){
//userselectmanage.
%>
<jsp:forwardpage="jsp7.jsp">
<jsp:paramname="username"value="<%=user%>"/>
<jsp:paramname="password"value="<%=pwd%>"/>
</jsp:forward>
<%
}else{
//userselectstatistic
%>
<jsp:forwardpage="jsp8.jsp">
<jsp:paramname="username"value="<%=user%>"/>
<jsp:paramname="password"value="<%=pwd%>"/>
</jsp:forward>
<%
}
%>
</body>
</html>
-----------------------------------------------------------------------------------------------
jsp7:
<%@pagecontentType="text/html;charset=GB2312"%>
<html>
<head>
<title>
jsp7
</title>
</head>
<bodybgcolor="#ffffff">
<h1>
这是办理页!!!
</h1>
<br>
<%
Stringuser,pwd;
user=request.getParameter("username");
pwd=request.getParameter("password");
%>
usernameis:<%=user%><br>
passwordis:<%=pwd%><br>
</body>
</html>
---------------------------------------------------------------------------------------------
jsp8:
<%@pagecontentType="text/html;charset=GB2312"%>
<html>
<head>
<title>
jsp8
</title>
</head>
<bodybgcolor="#ffffff">
<h1>
这是统计页!!!
</h1>
<br>
<%
Stringuser,pwd;
//user=request.getParameter("username");
user=newString(request.getParameter("username").getBytes("ISO8859_1"));
pwd=request.getParameter("password");
%>
usernameis:<%=user%><br>
passwordis:<%=pwd%><br>
</body>
</html>
----------------------------------------------------------------------------------------------------
input.html
<HTML>
<HEAD>
<TITLE>网页引诱</TITLE>
</HEAD>
<BODY>
<CENTER>
<FONTSIZE=5COLOR=blue>网页引诱</FONT>
</CENTER>
<BR>
<HR>
<BR>
<FORMaction="sendRedirect.jsp"method=postname=form1>
<P>姓名:<INPUTname=inputName></P>
<P>E-Mail:<INPUTname=inputE_Mail></P>
<INPUTname=submittype=submitvalue=送出>
</FORM>
</BODY>
</HTML
-----------------------------------------------------------------------------
sendRedirect.jsp:
<%@pagecontentType="text/html;charset=GB2312"%>
<%@pagelanguage="java"%>
<%
StringName=request.getParameter("inputName");
StringE_Mail=request.getParameter("inputE_Mail");
if(Name.equals("")||E_Mail.equals(""))//反省Name或E_Mail是不是完成材料输出
response.sendRedirect("sendRedirect.html");//若未完成材料输出则将网页导向sendRedirect.html
%>
<HTML>
<HEAD>
<TITLE>网页引诱</TITLE>
</HEAD>
<BODY>
<CENTER>
<FONTSIZE=5COLOR=blue>网页引诱</FONT>
</CENTER>
<BR>
<HR>
<BR>
<P>您的台甫是:
<%=Name%>
</P>
<P>E-Mail帐号为:
<%=E_Mail%>
</P>
<p><ahref="../jsp1.jsp">前往</a></p>
</BODY>
</HTML>
-----------------------------------------------------------------------------------
sendRedirect.html:
<HTML>
<HEAD>
<TITLE>网页引诱</TITLE>
</HEAD>
<BODY>
<CENTER>
<FONTSIZE=5COLOR=blue>网页引诱</FONT>
</CENTER>
<BR>
<HR>
<BR>
<FORMaction="sendRedirect.jsp"method=postname=form1>
<fontsize=5color=red>
你输出的信息不完全,请从头输出!
</font>
<br>
<P>姓名:<INPUTname=inputName></P>
<P>E-Mail:<INPUTname=inputE_Mail></P>
<INPUTname=submittype=submitvalue=送出>
</FORM>
</BODY>
</HTML>
专门做了这个例子;而java的这个例子好像就是为了教学而写的,很多教学目的的例子是不考虑优化、性能的。 |
|