CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  Web 开发

表单提交的问题 在线等

楼主duan17()2003-12-01 18:36:33 在 Java / Web 开发 提问

<%@   page   contentType="text/html;   charset=gb2312"   language="java"   import="java.sql.*"   errorPage=""   %>  
  <html>  
  <head>  
  <meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312">  
  <title>我的JSP</title>  
  </head>  
  <body>  
  <p>java   web   application   1</p>  
   
  <%  
  String   name1=request.getParameter("name1");  
  if     (name1==null){  
  %>  
  <form     action="jspform.jsp"   method="post">  
   
  <table   width="75%"   border="1">  
      <tr>    
          <td     bgcolor="#FFFF99"   align="right"   width="49%">姓名</td>  
          <td   width="51%"   colspan="2">  
                  <input   name="name1"   type="text"   id="name1">  
            </td>  
      </tr>  
      <tr>    
          <td   align="right">性别</td>  
          <td   colspan="2">  
                  <input   name="sex"   type="radio"   value="radiobutton"   checked>  
                  男    
                  <input   type="radio"   name="sex"   value="radiobutton">  
                  女    
              </td>  
      </tr>  
      <tr>    
          <td     bgcolor="#FFFF99"align="right">年龄</td>  
          <td   colspan="2"><select   name="age"   size="1">  
                      <option>20-30</option>  
                      <option>30-40</option>  
                      <option>50-60</option>  
                  </select></td>  
      </tr>  
      <tr>    
          <td   align="right">电子邮箱</td>  
          <td   colspan="2"><input   type="text"   name="mail"></td>  
      </tr>  
      <tr>  
          <td   bgcolor="#FFFF99"   align="right"   height="102">从事的职务</td>  
          <td   colspan="2"><select   name="titles"   size="3"   multiple>  
                      <option>程序员</option>  
                      <option>开发经理</option>  
                      <option>WEB设计人员</option>  
                      <option>数据库管理人员</option>  
                  </select></td>  
      </tr>  
      <tr>    
          <td   align="right"   height="41">你的爱好</td>  
          <td   colspan="2"><input   name="favor"   type="checkbox"   id="favor"   value="checkbox">  
                  sport    
                  <input   type="checkbox"   name="favor"   value="checkbox">  
                  travel    
                  <input   name="favor"   type="checkbox"   id="favor"   value="checkbox">  
                  music</td>  
      </tr>  
  </table>  
      <p>  
          <input   type="submit"   name="Submit"   value="提交">  
      </p>  
  </form>  
  <%  
  }else  
  {  
  try{  
  String   sex=request.getParameter("sex");  
  String   age=request.getParameter("age");  
  String     mail1=request.getParameter("mail1");  
  String[]   titles   =request.getParameterValues("titles");  
  String[]   favor   =request.getParameterValues("favor'");}  
  catch   (Exception   ex)  
  {  
              out.print(ex.getMessage());  
  }  
  %>  
  <p>你输入的信息如下</p>  
  <br>  
  <%=name1%>  
  <%=mail1%>  
  <%=sex%>  
  <%=age%>  
  <%  
  for   (int   i   =0;i<titles.length;i++)  
  {  
            out.print(titles[i]);  
  }  
  for   (int   j   =0;j<favor.length;j++)  
  {  
            out.print(favor[j]);  
  }  
  %>  
  <%}%>  
  </body>  
  </html>  
   
  各位帮我看一下是哪里错了 问题点数:100、回复次数:10Top

1 楼szpqq(Gavin)回复于 2003-12-01 18:50:55 得分 10

根据你自己输入的数据看看是输哪些数据错了,然后再在一些地方输入一些信息看看,看能不能找到问题,另外看变量在引用前是否得判断一下为空,例如  
  if(titles==null)  
      titles="";  
  Top

2 楼sandy91(雨儿)回复于 2003-12-01 18:59:55 得分 10

建议:把表单提交到另外一页,然后把变量都一一打印出来,可以帮助你排查一下错误!Top

3 楼lyqq(曾经是菜,现在还是菜!)回复于 2003-12-01 19:09:55 得分 0

<%=name1%>  
  <%=mail1%>  
  <%=sex%>  
  <%=age%>  
  这些变量的定义不应该在   try里面,因为try语句在if   else   中的else中,第一次执行时,不会执行到else中的语句,所以错误为无法解析变量!Top

4 楼lingee1999(网上邻居)回复于 2003-12-01 19:18:11 得分 40

这样即可:::  
   
  <%@   page   contentType="text/html;   charset=gb2312"   language="java"   import="java.sql.*"   errorPage=""   %>  
  <html>  
  <head>  
  <meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312">  
  <title>我的JSP</title>  
  </head>  
  <body>  
  <p>java   web   application   1</p>  
   
  <%  
  String   name1=request.getParameter("name1");  
  if     (name1==null){  
  %>  
  <form     action="jspform.jsp"   method="post">  
   
  <table   width="75%"   border="1">  
      <tr>  
          <td     bgcolor="#FFFF99"   align="right"   width="49%">姓名</td>  
          <td   width="51%"   colspan="2">  
                  <input   name="name1"   type="text"   id="name1">  
            </td>  
      </tr>  
      <tr>  
          <td   align="right">性别</td>  
          <td   colspan="2">  
                  <input   name="sex"   type="radio"   value="radiobutton"   checked>  
                  男  
                  <input   type="radio"   name="sex"   value="radiobutton">  
                  女  
              </td>  
      </tr>  
      <tr>  
          <td     bgcolor="#FFFF99"align="right">年龄</td>  
          <td   colspan="2"><select   name="age"   size="1">  
                      <option>20-30</option>  
                      <option>30-40</option>  
                      <option>50-60</option>  
                  </select></td>  
      </tr>  
      <tr>  
          <td   align="right">电子邮箱</td>  
          <td   colspan="2"><input   type="text"   name="mail"></td>  
      </tr>  
      <tr>  
          <td   bgcolor="#FFFF99"   align="right"   height="102">从事的职务</td>  
          <td   colspan="2"><select   name="titles"   size="3"   multiple>  
                      <option>程序员</option>  
                      <option>开发经理</option>  
                      <option>WEB设计人员</option>  
                      <option>数据库管理人员</option>  
                  </select></td>  
      </tr>  
      <tr>  
          <td   align="right"   height="41">你的爱好</td>  
          <td   colspan="2"><input   name="favor"   type="checkbox"   id="favor"   value="checkbox">  
                  sport  
                  <input   type="checkbox"   name="favor"   value="checkbox">  
                  travel  
                  <input   name="favor"   type="checkbox"   id="favor"   value="checkbox">  
                  music</td>  
      </tr>  
  </table>  
      <p>  
          <input   type="submit"   name="Submit"   value="提交">  
      </p>  
  </form>  
  <%  
  }else  
  {  
  String   sex="";  
  String   age="";  
  String     mail1="";  
  String[]   titles=null;  
  String[]   favor=null;  
  try{  
      sex=request.getParameter("sex");  
      age=request.getParameter("age");  
      mail1=request.getParameter("mail1");  
      titles   =request.getParameterValues("titles");  
      favor   =request.getParameterValues("favor'");}  
  catch   (Exception   ex)  
  {  
              out.print(ex.getMessage());  
  }  
  %>  
  <p>你输入的信息如下</p>  
  <br>  
  <%=name1%>  
  <%=mail1%>  
  <%=sex%>  
  <%=age%>  
  <%  
  if   (titles!=null)  
  for   (int   i   =0;i<titles.length;i++)  
  {  
            out.print(titles[i]);  
  }  
  if   (favor!=null)  
  for   (int   j   =0;j<favor.length;j++)  
  {  
            out.print(favor[j]);  
  }  
  %>  
  <%}%>  
  </body>  
  </html>  
  Top

5 楼lyqq(曾经是菜,现在还是菜!)回复于 2003-12-01 19:19:15 得分 40

大概改了一下,主要的改动都在后面!现在可以正常显示了!  
  提交以后还是有点问题,关系到中文显示的问题,和其他的一点问题。剩下的问题你自己应该可以解决!  
   
  <%@   page   contentType="text/html;   charset=gb2312"   language="java"   import="java.sql.*"   errorPage=""   %>  
  <html>  
  <head>  
  <meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312">  
  <title>我的JSP</title>  
  </head>  
  <body>  
  <p>java   web   application   1</p>  
   
  <%  
  String   name1=request.getParameter("name1");  
  if     (name1==null){  
  %>  
  <form     action="jspform.jsp"   method="post">  
   
  <table   width="75%"   border="1">  
      <tr>    
          <td     bgcolor="#FFFF99"   align="right"   width="49%">姓名</td>  
          <td   width="51%"   colspan="2">  
                  <input   name="name1"   type="text"   id="name1">  
            </td>  
      </tr>  
      <tr>    
          <td   align="right">性别</td>  
          <td   colspan="2">  
                  <input   name="sex"   type="radio"   value="radiobutton"   checked>  
                  男    
                  <input   type="radio"   name="sex"   value="radiobutton">  
                  女    
              </td>  
      </tr>  
      <tr>    
          <td     bgcolor="#FFFF99"align="right">年龄</td>  
          <td   colspan="2"><select   name="age"   size="1">  
                      <option>20-30</option>  
                      <option>30-40</option>  
                      <option>50-60</option>  
                  </select></td>  
      </tr>  
      <tr>    
          <td   align="right">电子邮箱</td>  
          <td   colspan="2"><input   type="text"   name="mail1"></td>  
      </tr>  
      <tr>  
          <td   bgcolor="#FFFF99"   align="right"   height="102">从事的职务</td>  
          <td   colspan="2"><select   name="title"   size="3"   multiple>  
                      <option>程序员</option>  
                      <option>开发经理</option>  
                      <option>WEB设计人员</option>  
                      <option>数据库管理人员</option>  
                  </select></td>  
      </tr>  
      <tr>    
          <td   align="right"   height="41">你的爱好</td>  
          <td   colspan="2"><input   name="favor"   type="checkbox"   id="favor"   value="checkbox">  
                  sport    
                  <input   type="checkbox"   name="favor"   value="checkbox">  
                  travel    
                  <input   name="favor"   type="checkbox"   id="favor"   value="checkbox">  
                  music</td>  
      </tr>  
  </table>  
      <p>  
          <input   type="submit"   name="Submit"   value="提交">  
      </p>  
  </form>  
  <%  
  }else  
  {  
  try{  
  String   sex=request.getParameter("sex");  
  String   age=request.getParameter("age");  
  String     mail1=request.getParameter("mail1");  
  String[]   titles   =request.getParameterValues("title");  
  String[]   favor   =request.getParameterValues("favor");  
  %>  
  <p>你输入的信息如下</p>  
  <br>  
  <%=name1%>  
  <%=mail1%>  
  <%=sex%>  
  <%=age%>  
  <%  
  for   (int   i   =0;i<titles.length;i++)  
  {  
            out.print(titles[i]);  
  }  
  for   (int   j   =0;j<favor.length;j++)  
  {  
            out.print(favor[j]);  
  }  
  }  
  catch   (Exception   ex)  
  {  
              out.print(ex.getMessage());  
  }  
   
  %>  
   
  <%  
   
  %>  
  <%}%>  
  </body>  
  </html>Top

6 楼tangyanjun1(唐延军)回复于 2003-12-01 19:22:21 得分 0

报了什么错误?Top

7 楼lyqq(曾经是菜,现在还是菜!)回复于 2003-12-01 19:22:50 得分 0

关于中文显示的问题,可以这样解决!  
   
  在开头部分,加入一句  
   
  <%@   page   contentType="text/html;   charset=gb2312"   language="java"   import="java.sql.*"   errorPage=""   %>  
  <%request.setCharacterEncoding("GBK");%>           //这句话是新加的!Top

8 楼lyqq(曾经是菜,现在还是菜!)回复于 2003-12-01 19:23:39 得分 0

解决后的完整代码如下:  
   
   
   
  <html>  
  <head>  
  <meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312">  
  <title>我的JSP</title>  
  </head>  
  <body>  
  <p>java   web   application   1</p>  
   
  <%  
  String   name1=request.getParameter("name1");  
  if     (name1==null){  
  %>  
  <form     action="jspform.jsp"   method="post">  
   
  <table   width="75%"   border="1">  
      <tr>  
          <td     bgcolor="#FFFF99"   align="right"   width="49%">姓名</td>  
          <td   width="51%"   colspan="2">  
                  <input   name="name1"   type="text"   id="name1">  
            </td>  
      </tr>  
      <tr>  
          <td   align="right">性别</td>  
          <td   colspan="2">  
                  <input   name="sex"   type="radio"   value="radiobutton"   checked>  
                  男  
                  <input   type="radio"   name="sex"   value="radiobutton">  
                  女  
              </td>  
      </tr>  
      <tr>  
          <td     bgcolor="#FFFF99"align="right">年龄</td>  
          <td   colspan="2"><select   name="age"   size="1">  
                      <option>20-30</option>  
                      <option>30-40</option>  
                      <option>50-60</option>  
                  </select></td>  
      </tr>  
      <tr>  
          <td   align="right">电子邮箱</td>  
          <td   colspan="2"><input   type="text"   name="mail"></td>  
      </tr>  
      <tr>  
          <td   bgcolor="#FFFF99"   align="right"   height="102">从事的职务</td>  
          <td   colspan="2"><select   name="titles"   size="3"   multiple>  
                      <option>程序员</option>  
                      <option>开发经理</option>  
                      <option>WEB设计人员</option>  
                      <option>数据库管理人员</option>  
                  </select></td>  
      </tr>  
      <tr>  
          <td   align="right"   height="41">你的爱好</td>  
          <td   colspan="2"><input   name="favor"   type="checkbox"   id="favor"   value="checkbox">  
                  sport  
                  <input   type="checkbox"   name="favor"   value="checkbox">  
                  travel  
                  <input   name="favor"   type="checkbox"   id="favor"   value="checkbox">  
                  music</td>  
      </tr>  
  </table>  
      <p>  
          <input   type="submit"   name="Submit"   value="提交">  
      </p>  
  </form>  
  <%  
  }else  
  {  
  String   sex="";  
  String   age="";  
  String     mail1="";  
  String[]   titles=null;  
  String[]   favor=null;  
  try{  
      sex=request.getParameter("sex");  
      age=request.getParameter("age");  
      mail1=request.getParameter("mail1");  
      titles   =request.getParameterValues("titles");  
      favor   =request.getParameterValues("favor'");}  
  catch   (Exception   ex)  
  {  
              out.print(ex.getMessage());  
  }  
  %>  
  <p>你输入的信息如下</p>  
  <br>  
  <%=name1%>  
  <%=mail1%>  
  <%=sex%>  
  <%=age%>  
  <%  
  if   (titles!=null)  
  for   (int   i   =0;i<titles.length;i++)  
  {  
            out.print(titles[i]);  
  }  
  if   (favor!=null)  
  for   (int   j   =0;j<favor.length;j++)  
  {  
            out.print(favor[j]);  
  }  
  %>  
  <%}%>  
  </body>  
  </html>Top

9 楼lyqq(曾经是菜,现在还是菜!)回复于 2003-12-01 19:24:34 得分 0

上一个落了一句话:  
   
  <%@   page   contentType="text/html;   charset=gb2312"   language="java"   import="java.sql.*"   errorPage=""   %>  
  <%request.setCharacterEncoding("GBK");%>  
  <html>  
  <head>  
  <meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312">  
  <title>我的JSP</title>  
  </head>  
  <body>  
  <p>java   web   application   1</p>  
   
  <%  
  String   name1=request.getParameter("name1");  
  if     (name1==null){  
  %>  
  <form     action="jspform.jsp"   method="post">  
   
  <table   width="75%"   border="1">  
      <tr>  
          <td     bgcolor="#FFFF99"   align="right"   width="49%">姓名</td>  
          <td   width="51%"   colspan="2">  
                  <input   name="name1"   type="text"   id="name1">  
            </td>  
      </tr>  
      <tr>  
          <td   align="right">性别</td>  
          <td   colspan="2">  
                  <input   name="sex"   type="radio"   value="radiobutton"   checked>  
                  男  
                  <input   type="radio"   name="sex"   value="radiobutton">  
                  女  
              </td>  
      </tr>  
      <tr>  
          <td     bgcolor="#FFFF99"align="right">年龄</td>  
          <td   colspan="2"><select   name="age"   size="1">  
                      <option>20-30</option>  
                      <option>30-40</option>  
                      <option>50-60</option>  
                  </select></td>  
      </tr>  
      <tr>  
          <td   align="right">电子邮箱</td>  
          <td   colspan="2"><input   type="text"   name="mail"></td>  
      </tr>  
      <tr>  
          <td   bgcolor="#FFFF99"   align="right"   height="102">从事的职务</td>  
          <td   colspan="2"><select   name="titles"   size="3"   multiple>  
                      <option>程序员</option>  
                      <option>开发经理</option>  
                      <option>WEB设计人员</option>  
                      <option>数据库管理人员</option>  
                  </select></td>  
      </tr>  
      <tr>  
          <td   align="right"   height="41">你的爱好</td>  
          <td   colspan="2"><input   name="favor"   type="checkbox"   id="favor"   value="checkbox">  
                  sport  
                  <input   type="checkbox"   name="favor"   value="checkbox">  
                  travel  
                  <input   name="favor"   type="checkbox"   id="favor"   value="checkbox">  
                  music</td>  
      </tr>  
  </table>  
      <p>  
          <input   type="submit"   name="Submit"   value="提交">  
      </p>  
  </form>  
  <%  
  }else  
  {  
  String   sex="";  
  String   age="";  
  String     mail1="";  
  String[]   titles=null;  
  String[]   favor=null;  
  try{  
      sex=request.getParameter("sex");  
      age=request.getParameter("age");  
      mail1=request.getParameter("mail1");  
      titles   =request.getParameterValues("titles");  
      favor   =request.getParameterValues("favor'");}  
  catch   (Exception   ex)  
  {  
              out.print(ex.getMessage());  
  }  
  %>  
  <p>你输入的信息如下</p>  
  <br>  
  <%=name1%>  
  <%=mail1%>  
  <%=sex%>  
  <%=age%>  
  <%  
  if   (titles!=null)  
  for   (int   i   =0;i<titles.length;i++)  
  {  
            out.print(titles[i]);  
  }  
  if   (favor!=null)  
  for   (int   j   =0;j<favor.length;j++)  
  {  
            out.print(favor[j]);  
  }  
  %>  
  <%}%>  
  </body>  
  </html>  
  Top

10 楼duan17()回复于 2003-12-01 19:46:56 得分 0

我先试一下Top

相关问题

  • 如何自动提交表单???(在线)
  • 表单提交问题,在线等待!!!
  • 表单提交问题,在线等候
  • 提交一个表单,多个页面的提交!在线等
  • 关于表单提交的问题(在线等待)
  • 再谈vbscript 提交表单问题 ???(在线)
  • 急,多表单提交问题,在线等
  • 关于表单提交的问题-急!在线等待
  • 关于表单的提交问题,在线等!
  • 关于表单提交的烦恼!!!(在线等.......)

关键词

得分解答快速导航

  • 帖主:duan17
  • szpqq
  • sandy91
  • lingee1999
  • lyqq

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo