注册 登录
编程论坛 J2EE论坛

不明白的错误

tiantiaqn 发布于 2007-07-05 11:37, 1050 次点击
The method Parameter(String) is undefined for the type HttpServletRequest
是什么意思呀?
16 回复
#2
食恶不色2007-07-05 11:44
方法参数(字符串)是未定义的类型
#3
tiantiaqn2007-07-05 11:51
谢咯
#4
tiantiaqn2007-07-05 11:53
String name=request.Parameter("name");
怎么会出现错误呢?
#5
tiantiaqn2007-07-05 11:54
String name=request.Parameter("name")
("name")是从前面获得字符串的呀
#6
食恶不色2007-07-05 12:01
能否把代碼帖出來。。
#7
食恶不色2007-07-05 12:03
你上面的代碼沒錯。。我不知道你代碼中還有沒有錯誤。。
#8
tiantiaqn2007-07-05 12:04


newtushu.jsp
<%@page contentType="text/html;charset=GB2312"%>
<%@page import="java.sql.*"%>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<html>
<body bgcolor=cyan>
<font size=2>
添加新的数据到数据库:
<form action="newresult.jsp" method=post>
图书名:<br>
<input type="text" name="name" >
<br>编号:<br>
<input type="text" name="bianhao">
<br>出版社名:<br>
<input type="text" name="chubanshe">
<br>作者:<br>
<input type="text" name="zuozhe">
<br>类别:<br>
<input type="text" name="leibie">
<br>
<input type="submit" name="submit" value="提交添加">
<p>添加前的记录是:
<%
String name,bianhao,chubanshe,zuozhe,leibie;
Connection con;
Statement sql;
ResultSet rs;
String str="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\datafile\\tushu1.mdb";
try
{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
try
{

con=DriverManager.getConnection(str,"","");
sql=con.createStatement();
rs=sql.executeQuery("Select * From tushu2");
out.print("<Table Border>");
out.print("<TR>");
out.print("<TH width=100>"+"编号");
out.print("<TH width=100>"+"图书名");
out.print("<TH width=100>"+"作者");
out.print("<TH width=100>"+"出版社名");
out.print("<TH width=100>"+"类别");

out.print("</TR>");
while(rs.next())
{
out.print("<TR>");
bianhao=rs.getString("编号");
out.print("<TD>"+bianhao+"</TD>");
name=rs.getString("图书名");
out.print("<TD>"+name+"</TD>");
zuozhe=rs.getString("作者");
out.print("<TD>"+zuozhe+"</TD>");
chubanshe=rs.getString("出版社名");
out.print("<TD>"+chubanshe+"</TD>");
leibie=rs.getString("类别");
out.print("<TD>"+leibie+"</TD>");

out.print("</TR>");
}
out.print("</Table>");
rs.close();
sql.close();
con.close();
;
}
catch(SQLException e1){}
%>
</form>
</font>
</body>
</html>


#9
食恶不色2007-07-05 12:06
這個好像沒有Request
#10
tiantiaqn2007-07-05 12:08

后面的jsp页就是获取
String name=request.Parameter("name")

#11
tiantiaqn2007-07-05 12:09

neuresult.jsp
<%@page contentType="text/html;charset=GB2312"%>
<%@page import="java.sql.*" import ="java.util.*"%>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<html>
<body bgcolor=cyan>
<%
String name=request.Parameter("name");
if(name==null)
{
name="";
}
byte b[]=name.getBytes("ISO-8859-1");
name=new String(b);
String chubanshe=request.Parameter("chubanshe");
if(chubanshe==null)
{
chubanshe="";
}
byte c[]=chubanshe.getBytes("ISO-8859-1");
chubanshe=new String(c);
String zuozhe=request.Parameter("zuozhe");
if(zuozhe==null)
{
zuozhe="";
}
byte d[]=zuozhe.getBytes("ISO-8859-1");
zuozhe=new String(d);
String leibie=request.Parameter("leibie");
if(leibie==null)
{
leibie="";
}
byte e[]=leibie.getBytes("ISO-8859-1");
leibie=new String(e);
String bianhao=request.Parameter("bianhao");
if(bianhao==null)
{
bianhao="";
}
byte f[]=bianhao.getBytes("ISO-8859-1");
bianhao=new String(f);
Connection con=null;
Statement sql=null;
ResultSet rs=null;
String nbianhao,nname,nchubanshe,nleibie,nzuozhe;
String str="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\datafile\\tushu1.mdb";
try
{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException event){}
try
{

con=DriverManager.getConnection(str,"","");
sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String condition="INSERT INTO tushu2 values "+"("+"'"+bianhao+"','"+name+"','"+zuozhe+"','"+chubanshe+"','"+leibie+"')";
sql.executeUpdate(condition);
%>
<p>添加后的记录:
<%
rs=sql.executeQuery("select * from tushu2");
out.print("<Table Border>");
out.print("<TR>");
out.print("<TH width=100>"+"编号");
out.print("<TH width=100>"+"图书名");
out.print("<TH width=100>"+"作者");
out.print("<TH width=100>"+"出版社名");
out.print("<TH width=100>"+"类别");

out.print("</TR>");
while(rs.next())
{
out.print("<TR>");
nbianhao=rs.getString("编号");
out.print("<TD>"+nbianhao+"</TD>");
nname=rs.getString("图书名");
out.print("<TD>"+nname+"</TD>");
nzuozhe=rs.getString("作者");
out.print("<TD>"+nzuozhe+"</TD>");
nchubanshe=rs.getString("出版社名");
out.print("<TD>"+nchubanshe+"</TD>");
nleibie=rs.getString("类别");
out.print("<TD>"+nleibie+"</TD>");

out.print("</TR>");
}
out.print("</Table>");
rs.close();
sql.close();
con.close();

}
catch(SQLException event){}
%>
</body>
</html>

#12
wbl3132007-07-05 12:38
以下是引用tiantiaqn在2007-7-5 12:08:23的发言:

后面的jsp页就是获取
String name=request.Parameter("name")

request有这个方法吗?
是request.get...吧

#13
tiantiaqn2007-07-05 12:39
哦,谢谢咯,非常感谢
#14
tiantiaqn2007-07-05 12:42
问题以解决
谢谢wbl313、食恶不色
#15
wbl3132007-07-05 12:49
最好不要在jsp页面写代码
这样出错不好维护
jsp最好只是起到一个显示的作用
#16
tiantiaqn2007-07-05 13:00
恩,你帮我看看,这句怎么写呀?

"UPDATE tushu2 SET tushu2.作者="+newzuozhe+"where tushu2.图书名="+"'"+name+"'"
#17
食恶不色2007-07-05 13:54
你要寫到那?
1