jsp页面与页面之间参数的传递【重点】

来源:互联网 发布:织梦cms 视频播放 编辑:程序博客网 时间:2024/05/17 23:08

1.第一种方式;前一个页面<a href='infor.jsp?id=<%=rs.getInt(1)%>通过?加参数传递

后一个页面String Id = request.getParameter("id");必须先用request得到,在进行对数据库的操作String s = "select * from mynews where news_id=" +Id;
   ResultSet rs = db.executeQuery(s);

 

 

 

2.第二种方式

前一个页面<textarea name="textare" cols="75" rows="24">

后一个页面String NewsText=request.getParameter("textare");

String str="update  mynews set news_text='"+NewsText+"'where news_id='"+Id+"'";
    int i=db.excuteUpdate(str);

 

前一个页面 <form action="change.jsp?news_id=<%=Id%>"method="post" name="form1">

后一个页面 String Id=request.getParameter("news_id");

String str="update  mynews set news_text='"+NewsText+"'wherenews_id='"+Id+"'";

 

 

第一个是关于字符串连接的:String sql="字符串A"+"字符串B"+"字符串C"这里的+符号的含义是把三个字符串拼接起来成为"字符串A字符串B字符串C",然后赋给字符串sql,其效果与下面的定义是一样的String sql="字符串A字符串B字符串C"

 

第二个问题是变量引用:sql=sql+" and sc.Sno='"+studentNo+"'";的含义是在现有的字符串sql后面继续拼接参数,这个参数是"+studentNo+",你前面不是判过if(! studentNo.equals(""))么,这个时候参数"+studentNo+"应该是一个确定的值如123456,拼接后的字符串sql为:字符串A字符串B字符串C and sc.Sno='123456'

 

 

 

原创粉丝点击