首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

为何

2011-12-26 
为什么?htmlbody%session.setAttribute( username ,session.getAttribute( username ))%formm

为什么?
<html>
<body>
<%session.setAttribute( "username ",session.getAttribute( "username "));%>
<form   method= "post "   action= "booksend.jsp ">
<table   width= "638 "   height= "314 "     border= "0 "   align= "center "   cellpadding= "0 "   cellspacing= "0 ">
    <!--DWLayoutTable-->

    <tr>
        <td   width= "612 "   height= "159 "   valign= "top "   background= "images/show.gif "   class= "word "> <p> &nbsp; </p>
        <p> &nbsp; </p>
        <p> &nbsp; </p>
        <p> &nbsp; </p>
        <p> &nbsp; </p>
        <blockquote>
            <p   align= "left ">   1&#65533;&#65533;   &#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#305;&#65533;&#65533;&#65533;&#65533;&#892;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#1211;&#65533;&#2303; </p>
            <p   align= "left ">
                    <input   name= "type "   type= "checkbox "     value= "kaifa "   >
            &#65533;&#65533;&#65533;&#65533;&#65533;&#1458;&#65533;
            <input   name= "type "   type= "checkbox "     value= "baili ">
            &#65533;&#65533;&#65533;&#65533;
            <input   name= "type "   type= "checkbox "     value= "jiqiao ">
            &#65533;&#65533;&#65533;&#65533;
            <input   name= "type "   type= "checkbox "     value= "shili ">
            &#693;&#65533;&#65533;&#65533;
            <input   name= "type "   type= "checkbox "     value= "jiaocheng ">
            &#65533;&#819;&#65533; </p>
            <p   align= "left "> 2&#65533;&#65533;   &#65533;&#65533;&#697;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#1457;&#65533;&#65533;&#65533;&#65533;&#65533;&#1339;&#760126;&#65533;? </p>
            <p   align= "left ">
                    <input   name= "type2 "   type= "checkbox "     value= "VB "   >
                VB
                <input   name= "type2 "   type= "checkbox "     value= "VC ">


                VC++
                <input   name= "type2 "   type= "checkbox "   value= "JAVA ">
                JAVA
                <input   name= "type2 "   type= "checkbox "     value= "DELPHI ">
                DELPHI
                <input   name= "type2 "   type= "checkbox "     value= "ASP ">
                ASP
                <input   name= "type2 "   type= "checkbox "     value= "ASPNET ">
                ASP.NET
                <input   name= "type2 "   type= "checkbox "     value= "JSP ">
                JSP
                <input   name= "type2 "   type= "checkbox "     value= "OTHER ">
                &#65533;&#65533;&#65533;&#65533; </p>
            <p> 3&#65533;&#65533;   &#65533;&#65533;&#65533;&#65533;&#1336;&#65533;&#11898;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#892;&#65533;&#65533;? </p>
            <p>
                    <input   name= "type3 "   type= "checkbox "   value= "rumen "   >
                &#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#892;&#65533;&#65533;
                <input   name= "type3 "   type= "checkbox "     value= "jiangjie ">
                &#65533;&#65533;&#65533;&#65533;+&#693;&#65533;&#65533;
                <input   name= "type3 "   type= "checkbox "     value= "wanquan ">
                &#65533;&#65533;&#555;&#693;&#65533;&#65533;
                <input   name= "type3 "   type= "checkbox "     value= "baili ">
                &#65533;&#65533;&#65533;&#65533;&#65533;&#65533;
                <input   name= "type3 "   type= "checkbox "     value= "jiqiao ">
                &#65533;&#65533;&#65533;&#65533;&#65533;&#65533; </p>
        </blockquote>  
            <p   align= "center ">


                <input   type= "submit "   name= "aa "   value= "&#65533;&#8059; ">
            </p>
        <p   align= "left "> &nbsp; </p> </td>
    </tr>
</table>
</body>
</html>

-------------------------------


<%@   page   contentType= "text/html;charset=gb2312 "   language= "java "   import= "java.sql.*,java.io.* "%>
<%@   include   file= "include.inc "%>
<%session.setAttribute( "username ",session.getAttribute( "username "));%>
<html>
<style   type= "text/css ">
<!--
.style1   {font-size:   18px}
-->
</style>
<body>
<%

Class.forName(CLASSFORNAME);
Connection   con=DriverManager.getConnection(SERVER,USER,PWD);
Statement   stmt=con.createStatement();
String   type[]=request.getParameterValues( "type ");
String   type2[]=request.getParameterValues( "type2 ");
String   type3[]=request.getParameterValues( "type3 ");
%>
<%
if(type!=null)
{
for(int   i=0;i <type.length;i++)
{
String   aa=type[i];
try
{
stmt.executeUpdate( "update   tb_book   set   "+aa+ "=   "+aa+ "   +   1   where   id=1 ");

}
catch(Exception   e)
{
e.printStackTrace();
}

}
}

if(type2!=null)
{
for(int   i=0;i <type2.length;i++)
{
String   aa=type2[i];

try
{
stmt.executeUpdate( "update   tb_language   set   "+aa+ "=   "+aa+ "   +   1   where   id=1 ");
}
catch(Exception   e)
{
e.printStackTrace();
}
}
}

if(type3!=null)
{
for(int   i=0;i <type3.length;i++)
{
String   aa=type3[i];

try
{
stmt.executeUpdate( "update   tb_borrowbook   set   "+aa+ "=   "+aa+ "   +   1   where   id=1 ");
}
catch(Exception   e)
{
e.printStackTrace();
}
}
}


%>
<%
ResultSet   rs1=stmt.executeQuery( "select   *   from   tb_book   where   id=1 ");
if(rs1.next())
{
%>
<center> <h2> 明日科技   图书市场调研卡 </h2>

<table   width= "567 "   height= "176 ">
    <tr> <td> <h3> 调查结果: </h3> </tr> </td>
    <tr> <td> <h4> 1、您经常购买的编程类图书属于哪一类? </h4> </td> </tr>
    <tr> <td>
            开发手册类得票: <%=rs1.getString( "kaifa ")%> 票 <br>
            百例类得票: <%=rs1.getString( "baili ")%> 票 <br>
            技巧类: <%=rs1.getString( "jiqiao ")%> 票 <br>
            实例集锦类: <%=rs1.getString( "shili ")%> 票 <br>


            教程类: <%=rs1.getString( "jiaocheng ")%> 票
    </td> </tr>
<%
}
ResultSet   rs2=stmt.executeQuery( "select   *   from   tb_language   where   id=1 ");
if(rs2.next())
{
%>
<tr> <td> <h4> 2、您使用下面哪种编程语言或工具? </h4> </td> </tr>
    <tr> <td>
      VB得票: <%=rs2.getString( "VB ")%> 票 <br>
        VC++得票: <%=rs2.getString( "VC ")%> 票 <br>
        JAVA得票: <%=rs2.getString( "JAVA ")%> 票 <br>
        DELPHI得票: <%=rs2.getString( "DELPHI ")%> 票 <br>
        ASP得票: <%=rs2.getString( "ASP ")%> 票 <br>
        ASP.NET得票: <%=rs2.getString( "ASPNET ")%> 票 <br>
        JSP得票: <%=rs2.getString( "JSP ")%> 票 <br>
        其他得票: <%=rs2.getString( "OTHER ")%> 票
    </td> </tr>

<%
}
ResultSet   rs3=stmt.executeQuery( "select   *   from   tb_borrowbook   where   id=1 ");
if(rs3.next())
{
%>
<tr> <td> <h4> 3、您最愿意购买或借阅哪类图书? </h4> </td> </tr>
    <tr> <td>
   
      入门类图书得票: <%=rs3.getString( "rumen ")%> 票 <br>
      讲解+实例类得票: <%=rs3.getString( "jiangjie ")%> 票 <br>
      完全实例类得票: <%=rs3.getString( "wanquan ")%> 票 <br>
      百例型类得票: <%=rs3.getString( "baili ")%> 票 <br>
      技巧类得票: <%=rs3.getString( "jiqiao ")%> 票 <br>
   
    </td> </tr>
<%}
%>
</table>
<p   align= "center "   class= "style1 "> <a   href= "tuichu.jsp "> 退出 </a> </p>
</body>
</html>
------------------------------


为什么 写不进去!!!!!!!!!!!页面根本没反映 数据库保证能连上 但写不进去数据!




[解决办法]
"update tb_borrowbook set "+aa+ "= "+aa+ " + 1 where id=1 "
sql语句的语法有问题set后边应该是字段名,你那怎么是变量名,还是先在查询分析器试好了再往程序里放吧.
[解决办法]
stmt.executeUpdate( "update tb_borrowbook set "+aa+ "= "+aa+ " + 1 where id=1 ");
1.首先有楼上说的问题,但不全是,只要你确定字段名,使用变量名一样OK
如果以type为例,aa变量值为 "kaifa "时
stmt.executeUpdate( "update tb_borrowbook set "+aa+ "= "+aa+ " + 1 where id=1 ");
==
stmt.executeUpdate( "update tb_borrowbook set kaifa= kaifa + 1 where id=1 ");
其中kaifa + 1你作什么理解?

2.没用过这种方法,在我的印象中一个statement只有一次作用,另一种说法就是你中for循环多次调用同一个statement是没有用的,改正为batch方式,在for循环中添加batch,for循环完成后执行batch.

3.另外建议.别在for循环中写try...catch

热点排行