日期:2014-05-18  浏览次数:20779 次

JSP页面刷新两次的奇怪问题
在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>

------解决方案--------------------
lz就判断一下:if(null!=request.getParameter( "lid "))然后取值应该就可以了。
------解决方案--------------------
执行两遍?你确定?你在reply.jsp中加一句话打印下日志,看打印了几次.
至于取不到值那个等这个解决/确定了再说.别什么东西都放session中去.