jsp编的 两个页面index和update,从index获取一个name参数到update,老是为空值,而index中明明不是空值 15
附上一点代码~~我没有多少财富值。。。好心人帮忙看看吧index中代码:<body><%request.setCharacterEncoding("GBK");respo...
附上一点代码~~我没有多少财富值。。。好心人帮忙看看吧
index中代码:
<body>
<%
request.setCharacterEncoding("GBK");
response.setContentType("text/html;charset=GB2312");
try{
String spath="test.mdb";
String dbpath=application.getRealPath(spath);
String dbname="";
String user="";
String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+dbpath;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = "select * from 成绩表";
ResultSet rs = stmt.executeQuery(sql);
%>
<!--********创建一个表格,用以显示数据库中的各条记录******-->
<table align="center" border="1">
<caption><h3>学生成绩</h3></caption>
<tr><td colspan="4"><a href="add.htm">添加记录</a></td></tr>
<tr><td align="center">姓名</td><td align="center">所在学院</td><td align="center">成绩</td><td align="center">状态</td>
<%
String strname,strname2;
while(rs.next())
{
out.print("<tr align='center'>");
//out.print("<td>" + (strname=rs.getString("姓名"))+"</td>");
strname=rs.getString("姓名");
out.print("<td>"+strname+"</td>");
//out.print("<td>" + rs.getString("所在学院")+"</td>");
out.print("<td>" + (strname2=rs.getString(2))+"</td>");
//out.print("<td>" + rs.getString("成绩")+"</td>");
out.print("<td>" + (strname2=rs.getString(3))+"</td>");
//重点大概是这里
out.print("<td><a href='update.jsp? name="+strname+"'>修改</a><a href='delete.jsp? name="+strname+"'>||删除</a></td>");
update代码
<body>
<%
request.setCharacterEncoding("GBK");
response.setContentType("text/html;charset =GBK");
//这里有问题么?怎么就空值
String name=request.getParameter("name");
try{ String spath="test.mdb";
String dbpath=application.getRealPath(spath);
String dbname="";
String user="";
String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+dbpath;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = "select * from 成绩表 where 姓名='" +name+"'";
ResultSet rs=stmt.executeQuery(sql);
rs.next();
//这里执行时显示错误 所以name是空的 没取到参数值。。。为什么会这样啊
if(!rs.next()){out.print("错误"); }
if(rs.next())
{
String sname=rs.getString("姓名");
String department=rs.getString("所在学院");
String score=rs.getString("成绩");
%>
怎么。。。 我难道用的不是URL传值? 好心人帮我改下吧 展开
index中代码:
<body>
<%
request.setCharacterEncoding("GBK");
response.setContentType("text/html;charset=GB2312");
try{
String spath="test.mdb";
String dbpath=application.getRealPath(spath);
String dbname="";
String user="";
String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+dbpath;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = "select * from 成绩表";
ResultSet rs = stmt.executeQuery(sql);
%>
<!--********创建一个表格,用以显示数据库中的各条记录******-->
<table align="center" border="1">
<caption><h3>学生成绩</h3></caption>
<tr><td colspan="4"><a href="add.htm">添加记录</a></td></tr>
<tr><td align="center">姓名</td><td align="center">所在学院</td><td align="center">成绩</td><td align="center">状态</td>
<%
String strname,strname2;
while(rs.next())
{
out.print("<tr align='center'>");
//out.print("<td>" + (strname=rs.getString("姓名"))+"</td>");
strname=rs.getString("姓名");
out.print("<td>"+strname+"</td>");
//out.print("<td>" + rs.getString("所在学院")+"</td>");
out.print("<td>" + (strname2=rs.getString(2))+"</td>");
//out.print("<td>" + rs.getString("成绩")+"</td>");
out.print("<td>" + (strname2=rs.getString(3))+"</td>");
//重点大概是这里
out.print("<td><a href='update.jsp? name="+strname+"'>修改</a><a href='delete.jsp? name="+strname+"'>||删除</a></td>");
update代码
<body>
<%
request.setCharacterEncoding("GBK");
response.setContentType("text/html;charset =GBK");
//这里有问题么?怎么就空值
String name=request.getParameter("name");
try{ String spath="test.mdb";
String dbpath=application.getRealPath(spath);
String dbname="";
String user="";
String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+dbpath;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = "select * from 成绩表 where 姓名='" +name+"'";
ResultSet rs=stmt.executeQuery(sql);
rs.next();
//这里执行时显示错误 所以name是空的 没取到参数值。。。为什么会这样啊
if(!rs.next()){out.print("错误"); }
if(rs.next())
{
String sname=rs.getString("姓名");
String department=rs.getString("所在学院");
String score=rs.getString("成绩");
%>
怎么。。。 我难道用的不是URL传值? 好心人帮我改下吧 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询