在MAIN.JSP中,一个链接请求如下:
out.println("<a href=reply.jsp?lid="+rs.getInt("LID")+">回复</a>");
因为要传递LID参数,所以在reply.jsp中采用request.getParameter("lid")接收,但是reply.jsp页面会执行两次,第一次执行中在浏览器里是看不到页面的,也就是页面并不出现,只有第一次执行完了,页面才显示出来,这个时候,就不能得到LID了,是我程序的什么地方出了问题?请高手指点,万分感谢!!
reply.jsp代码如下,由于是练习用,写得很乱,请见谅:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK"/>
<title>reply</title>
</head> <jsp:useBean id="user_op" class="portlet_blog.User_Op"/>
<jsp:useBean id="db_op" class="portlet_blog.DB_Op"/>
<%--
if (user_op.getAuthority()!=1)
{
out.println("Yor have not allow into this page!");
return;
}
--%>
<center>
<form action="" method="GET">
<textarea name="reply" cols="50" rows="30"></textarea>
<input type="submit" name="submit" value="Submit" />
<input type="reset" value="Reset"/>
<%
int lid= Integer.parseInt(request.getParameter("lid"));
//int lid2=Integer.parseInt(session.getAttribute("lid"));
request.setCharacterEncoding("GBK");
//String strLog=;
if (request.getParameter("reply")!=null)
{
db_op.Insert_rep(request.getParameter("reply"),user_op.getUsername(),lid);
out.println("successful");
%>
<jsp:forward page="view.jsp"/>
<%}%>
</form>
</center>
</html>
out.println("<a href=reply.jsp?lid="+rs.getInt("LID")+">回复</a>");
因为要传递LID参数,所以在reply.jsp中采用request.getParameter("lid")接收,但是reply.jsp页面会执行两次,第一次执行中在浏览器里是看不到页面的,也就是页面并不出现,只有第一次执行完了,页面才显示出来,这个时候,就不能得到LID了,是我程序的什么地方出了问题?请高手指点,万分感谢!!
reply.jsp代码如下,由于是练习用,写得很乱,请见谅:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK"/>
<title>reply</title>
</head> <jsp:useBean id="user_op" class="portlet_blog.User_Op"/>
<jsp:useBean id="db_op" class="portlet_blog.DB_Op"/>
<%--
if (user_op.getAuthority()!=1)
{
out.println("Yor have not allow into this page!");
return;
}
--%>
<center>
<form action="" method="GET">
<textarea name="reply" cols="50" rows="30"></textarea>
<input type="submit" name="submit" value="Submit" />
<input type="reset" value="Reset"/>
<%
int lid= Integer.parseInt(request.getParameter("lid"));
//int lid2=Integer.parseInt(session.getAttribute("lid"));
request.setCharacterEncoding("GBK");
//String strLog=;
if (request.getParameter("reply")!=null)
{
db_op.Insert_rep(request.getParameter("reply"),user_op.getUsername(),lid);
out.println("successful");
%>
<jsp:forward page="view.jsp"/>
<%}%>
</form>
</center>
</html>
能够有什么办法在通过链接进行页面跳转的时候传递参数吗?
out.println("<a href=reply.jsp?lid="+rs.getInt("LID")+">回复</a>");
我这条语句是一个对数据库查询结果的循环体中的一句,采用这种方式的目的就是为了能够在点击"回复"的时候,把这条信息相应的LID传到reply.jsp页面去.还有什么别的方式吗??
<%
if(request.getParameter("lid")!=null)
{
int lid= Integer.parseInt(request.getParameter("lid"));
int int_lid=Integer.parseInt(session.getAttribute("sta_lid").toString());
if (int_lid==0&&int_lid!=lid)
session.setAttribute("sta_lid",lid);
}
request.setCharacterEncoding("GBK");
//String strLog=;
if (request.getParameter("reply")!=null)
{
int int_lid1=Integer.parseInt(session.getAttribute("sta_lid").toString());
db_op.Insert_rep(request.getParameter("reply"),user_op.getUsername(),int_lid1);
out.println("successful");
%>
至于取不到值那个等这个解决/确定了再说.别什么东西都放session中去.
我开始就是这样判断的,但是第2次肯定取不到lid,因为生成了一个新的request,所以lid为空,这样判断了我也没有办法得到,所以采用了我后来的办法,传到session里去
我后来调试才发现我的问题错误了,不是执行了两遍,因为我在reply.jsp里面有一个submit,需要提交textarea的东西,所以会有一个新的request,在submit的时候就无法取得从main.jsp里面传过来的lid,所以用了后来的笨办法,不知道有没有什么更好的办法可以解决这个传递问题