问题描述
汗!代码比较多!但是真的不知道为什么会错,请教高手,十分感谢!!!<%@pagelanguage="java"contentType="text/html;charset=gb2312"import="java.util.*,java.sql.*"pageEncoding="GB2312"%><linkrel="stylesheet"href="css/code43.css"type="text/css"><HTML><HEAD><title>查询数据并求和</title><scriptlanguage="javascript">functionbuy(){document.form1.submit();}functioncheck(){varuname=document.all("regname").value;varname=document.all("hid").value;vardatetype1=/^[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}$/;if(uname!=name){alert("输入的用户不正确");returnfalse;}elseif(!(datetype1.exec(document.form.xfdate.value))){alert("输入的日期格式不正确,请仔细检查!");document.form.xfdate.focus();returnfalse;}elseif(document.form.cqmoney.value==""){alert("金额不能为空");document.form.cqmoney.focus();returnfalse;}else{form.action="cqaction";form.target="_parent";form.submit();}}</script><METAhttp-equiv=Content-Typecontent="text/html;charset=gb2312"></HEAD><BODYstyle=scrollbar-arrow-color:#227776;scrollbar-base-color:#C6DCDEtext=#000000bgColor=#ffffffleftMargin=0topMargin=0background="img/bg.gif"marginwidth="0"marginheight="0"><formname="form"method="post"><divalign="center"><tablewidth="959"height="585"border="0"><inputtype="hidden"id="hid"name="hid"value="<%=(String)session.getAttribute("user")%>"/><tr><tdheight="33"colspan="5"align="right">用户名</td><tdwidth="508"height="33"align="right"><label><divalign="left"><inputtype="text"name="regname"></div></label></td><tdwidth="82"rowspan="5"> </td></tr><tr><tdheight="33"colspan="5"align="right">存钱时间</td><tdheight="33"align="right"><label><divalign="left"><inputtype="text"name="cqdate"></div></label></td></tr><tr><tdheight="33"colspan="5"align="right">存钱银行</td><tdheight="33"align="right"><divalign="left"><selectname="cqbank"id="cqbank">//以下代码报错<%request.setCharacterEncoding("gb2312");StringstrError=null;Stringuserid=(String)session.getAttribute("user");try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connectioncon=DriverManager.getConnection("jdbc:odbc:goodschaginfo");Statementstmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);Stringsql="selectcqselectfromselectformwhereregnamelike'%"+userid+"%'";ResultSetrs=stmt.executeQuery(sql);while(rs.next()){%><optionvalue="<%=rs.getString("cqselect")%>"><%=rs.getString("cqselect")%></option><%}rs.close();stmt.close();con.close();}catch(ClassNotFoundExceptione){strError=e.toString();}catch(SQLExceptione){strError=e.toString();}%></select></div></td></tr><tr><tdheight="33"colspan="5"align="right">存多少钱</td><tdheight="33"align="right"><label><divalign="left"><inputtype="text"name="cqmoney"></div></label></td></tr><tr><tdheight="33"colspan="5"align="right">备注</td><tdheight="33"align="right"><label><divalign="left"><inputtype="text"name="cqbeizhu"></div></label></td></tr><tr><tdheight="51"colspan="3"align="center"><label><inputtype="submit"name="Submit"value="提交"></label></td><tdheight="51"colspan="3"align="center"><inputtype="button"name="Submit2"value="返回"onClick="window.history.go(-1);"></td></tr></table></div></form></TD></td></tr></table></BODY></HTML>
解决方案
解决方案二:
是运行的时候报错:typeExceptionreportmessagedescriptionTheserverencounteredaninternalerror()thatpreventeditfromfulfillingthisrequest.exceptionorg.apache.jasper.JasperException:UnabletocompileclassforJSP:Anerroroccurredatline:89inthejspfile:/cunqian.jspDuplicatelocalvariableuserid86:<%87:request.setCharacterEncoding("gb2312");88:StringstrError=null;89:Stringuserid=(String)session.getAttribute("user");90:91:92:Stacktrace:org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)javax.servlet.http.HttpServlet.service(HttpServlet.java:717)noteThefullstacktraceoftherootcauseisavailableintheApacheTomcat/6.0.18logs.
解决方案三:
Stringuserid=(String)session.getAttribute("user");你存在session中的是user对象吧!如果说你存在session中的是user对象,那用String接受,肯定会报错的!
解决方案四:
Stringuserid=(String)session.getAttribute("user");你存在session中的是user对象吧!如果说你存在session中的是user对象,那用String接受,肯定会报错的!
解决方案五:
Stringuserid=(String)session.getAttribute("user");你存在session中的是user对象吧!如果说你存在session中的是user对象,那用String接受,肯定会报错的!
解决方案六:
引用4楼liutianxiong888的回复:
Stringuserid=(String)session.getAttribute("user");你存在session中的是user对象吧!如果说你存在session中的是user对象,那用String接受,肯定会报错的!
完全同意。
解决方案七:
Anerroroccurredatline:89inthejspfile:/cunqian.jspDuplicatelocalvariableuserid86:<%87:request.setCharacterEncoding("gb2312");88:StringstrError=null;89:Stringuserid=(String)session.getAttribute("user");90:91:92:错误提示说的清清楚楚的Duplicatelocalvariableuserid重复的本地变量userid