安全中国首页 > 编程中心 > JSP编程
 
安全中国网友投稿专用上传FTP空间:
Ftp服务器:download.anqn.com
Ftp端口:21
用户名:anqn
密 码:anqn.com
 

JSP:页面设计[6]

更新时间:2008-7-2 15:57:12
责任编辑:池天
热 点:

交到的operate_u.jsp源代码如下。
  operate_u.jsp
  <%@ page contentType="text/html; charset=gb2312" language="java" import="java. sql.*" errorPage="" %>
  <%@page import="java.util.Date"%>
  <%@page import="java.util.*"%>
  <%@page import="java.text.*"%>
  <%@ include file="conn.jsp" %>
  <%
  String username=new   String(request.getParameter("username").getBytes("iso-8859-1"));
  String userpwd=new   String(request.getParameter("userpwd").getBytes("iso-8859-1"));
  String name=new   String(request.getParameter("name").getBytes("iso-8859-1"));
  String qq = new   String(request.getParameter("qq").getBytes("iso-8859-1"));
  String email = new   String(request.getParameter("email").getBytes("iso-8859-1"));
  String http = new   String(request.getParameter("http").getBytes("iso-8859-1"));
  String sex=new   String(request.getParameter("sex").getBytes("iso-8859-1"));
  Date currTime = new Date();
  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
  String ftime=new   String(formatter.format(currTime).getBytes("iso-8859-1"));
  String condition="insert into guestbook_user   (username,userpwd,name,qq,email, http,regtime,sex)   values('"+username+"','"+userpwd+"','"+name+"','"+qq+"','"+email+"',

'"+http+"','"+ftime+"','"+sex+"')";
  stmt.executeUpdate(condition);
  stmt.close();
  conn.close();
  response.sendRedirect("index.jsp");
  %>
  这段程序就是接收上一个页面表单提交过来的值,对应到相应的字段并写入guestbook_user表中,这里有一点要注意的是,对于有可能出现中文的值在写入数据库之前必须要先进行编码转换,即如:Stringusername=newString(request.getParameter("username").getBytes("iso-8859-1"));就是以iso-8859-1编码的方式接收表单信息,并转换为页面默认编码(这里是gb2312),这样就可以避免出现中文乱码问题。


  下面来介绍用户添加留言页面中的主要部分。
add.jsp
 <%if (null == session.getAttribute("userid")){%>
        <tr valign="top">
          <td colspan="2" align="center"> <form name="form1" method="post" action="?act=login">
              <table width="60%" cellspacing="0" cellpadding="0">
                <tr>
                  <td height="25" align="right" class="font0">用户名:</td>
                  <td><input name="username" type="text" id="username" style="border: 1px double rgb(187,185,185);font:9pt"></td>
                </tr>
                <tr>
                  <td height="25" align="right" class="font0">密码:</td>
                  <td><input name="userpwd" type="password" id="userpwd" style= "border:1px double rgb(187,185,185);font:9pt"></td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td><input type="submit" name="Submit3" value="登录" style="border: 1 solid #BBB9B9;background:#ffffff" class="button"></td>
                </tr>
              </table>
            </form></td>
        </tr>
        <form action="operate_m.jsp" method="POST" name="form" id="form" onsubmit= "return check()">
          <tr valign="top">
            <td height="162" colspan="2" valign="top"> <table width="100%" border="0" cellpadding="0" cellspacing="2" class="tittle1">
                <tr>
                  <td width="70" height="21" align="right"><font color="#000099"><img src="img/Forum_nav.gif" width="15" height="19" align="absmiddle">
                    <span class="font0">姓名:</span></font></td>
                  <td width="180" height="30"> <input name="name" type="text" id="name" style="border:1px double rgb(187,185,185);font:9pt">
                    <font color="#FF0000">*</font> </td>
                  <td rowspan="4" valign="top"> <table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td><font color="#000099"><img src="img/shareforum.gif" width="25" height="25" align="absmiddle">
                          <span class="font0">留言内容:</span></font></td>
                      </tr>
                      <tr>
                        <td align="center"> <textarea name="content" cols="55" rows="5" id="content" style="border:1px double rgb(187,185,185);font:9pt"></textarea>
                          <font color="#FF0000">*</font> </td>
                      </tr>
                    </table></td>
                </tr>
                <tr>
                  <td align="right"><font color="#000099"><img src="img/topicnew. gif" width="16" height="18" align="absmiddle"><span class="font0">
                    性别:</span></font></td>
                  <td height="30"> <span class="font0">男孩</span> <input type="radio" name="sex" value="0" checked>
                    <span class="font0">女孩</span> <input type="radio" name="sex" value="1">
                  </td>
                </tr>
                <tr>
                  <td height="21" align="right"><font color="#000099"><img src="img/ topichot2.gif" width="16" height="18" align="absmiddle"><span class="font0">
                    OICQ:</span></font></td>
                  <td height="30"> <input name="qq" type="text" id="qq" style= "border:1px double rgb(187,185,185);font:9pt">
                  </td>
                </tr>
                <tr>
                  <td height="21" align="right"><font color="#000099"><img src="img/ topichotnonew.gif" width="16" height="18" align="absmiddle"><span class="font0"> Email:</span></font></td>
                  <td height="30"> <input name="email" type="text" id="email" style="border:1px double rgb(187,185,185);font:9pt">
                  </td>
                </tr>
                <tr>
                  <td height="21" align="right"><font color="#000099"><img src="img/ topicnonew.gif" width="16" height="18" align="absmiddle">
                    <span class="font0">主页:</span></font></td>
                  <td height="30"> <input name="http" type="text" id="http" style="border:1px double rgb(187,185,185);font:9pt" value="http://">
                  </td>
                  <td align="center"> <input type="submit" name="Submit" value="提交留言" style="border:1 solid #BBB9B9;background:#ffffff" class="button">
                    <input type="reset" name="Submit2" value="取消重写" style="border: 1 solid #BBB9B9;background:#ffffff" class="button">
                  </td>
                </tr>
              </table></td>
          </tr>
        </form>
  <%}else{%>
        <form action="operate_m.jsp" method="POST" name="form2" id="form2" onsubmit= "return check()">
        <tr>
          <td width="50">&nbsp;</td>
          <td><font color="#000099"><img src="img/shareforum.gif" width="25" height= "25" align="absmiddle">
            <span class="font0">留言内容:</span></font></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><textarea name="content" cols="55" rows="5" id="content" style= "border:1px double rgb(187,185,185);font:9pt"></textarea>
            <font color="#FF0000">*</font> </td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type="submit" name="Submit4" value="提交留言" style="border:1 solid #BBB9B9;background:#ffffff" class="button">
            <input type="reset" name="Submit22" value="取消重写" style="border:1 solid #BBB9B9;background:#ffffff" class="button">
          </td>
        </tr>
        </form>
  <%}%>
  这段程序中包含了注册用户留言和非注册用户留言两个部分,系统根据session.getAttribute ("userid")的值是否为空来判断是否为已注册并登录用户留言。

 
学习软件编程开发技术,推荐加入以下软件编程培训班:
易语言软件编程培训班(简单易学)  Delphi软件编程培训班  VC++软件编程培训班
VB软件编程培训班  JAVA高端编程就业研发班

学习网站开发制作技术,推荐加入以下网站开发培训班:
ASP.net网站开发项目实战班  ASP语言网站建设培训班

学习网络安全入侵防护技术,推荐加入以下技术培训班:
大型网络安全入侵防护班  网站脚本程序全方位安全检测班

学习网络管理、网吧运营维护技术(网管),推荐加入以下培训班:
大型网吧技术管理人才特训班  Linux网络嵌入架构工程师培训班

学习专项特殊技术,推荐加入以下专项技术培训班:
软件与游戏外挂脱壳破解班(逆向工程)  赚钱王道-网赚技能培训班  Flash动画设计师就业特训班

 
相关编程
一日一文章
 
一日一软件
一日一动画