完整代码为:<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
posttoself
</title>
</head>
<body bgcolor="#ffffff">
<h1>Post to self test</h1>
<form method="post" >
<br>请输入一个数字   :  <input name="num"><br>
<input type="submit" name="Submit" value="提交" >
<input type="reset" value="清除">
<br>你输入的数字是<%=request.getParameter("num")%>
<%
if (request.getParameter("num")=="22")
{out.write("恰好是你的年龄哦:)");
}
%>
<br>
</form>
</body>
</html>

解决方案 »

  1.   

    request.getParameter("num").equals("22")
      

  2.   

    <%
    if (request.getParameter("num").equals("22"))
    {out.write("恰好是你的年龄哦:)");
    }
    %>
      

  3.   

    if (request.getParameter("num")!=null)
    {
    if (request.getParameter("num").equals("22"))
    {out.write("恰好是你的年龄哦:)");
    }
    }最好写成这样,不然的话,第一次运行时,由于request.getParameter("num")==null,会导致
    request.getParameter("num").equals("22")出错.
      

  4.   

    字符串是对象,所以应该用.equals()比较,
    primitives用==比较
      

  5.   

    <%
    if (request.getParameter("num").equals("22"))
    {%>
    <H1><%="恰好是你的年龄哦:)");"%></H1>
    <%
      }
    %>  
      

  6.   

    <%
    if (request.getParameter("num").equals("22"))
    {
        out.write("恰好是你的年龄哦:)");
    }
    %>
      

  7.   

    刚才改了,还是出不来:(to gaojunbo(飞马----结网ing):每次都需要判断是否为空吗???刚才又测试了一下,
    地址栏输入:http://localhost:8080/gb/posttoself.jsp
    为空的时候出现下面的错误: The server encountered an internal error () that prevented it from fulfilling this request.但是即使http://localhost:8080/gb/posttoself.jsp?num=22
    第一次显示出"
    恰好是你的年龄哦:)"
    之后,
    再输入其它字符,
    这句话仍然输出了出来:(我,我快郁闷死了,就前两天才出的错误:(
      

  8.   

    呵呵!你这样写真是少见。
    <%@ page contentType="text/html; charset=GBK" %>
    <html>
    <head>
    <title>
    posttoself
    </title>
    </head>
    <body bgcolor="#ffffff">
    <%
    if(request.getParameter("num")=="22")
    {
      out.write("恰好是你的年龄哦:)");
    }
    %>
    <h1>Post to self test</h1>
    <form method="post" action="yourJspPath">
      <br>
        请输入一个数字   :  <input name="num">
      <br>
      <input type="submit" name="Submit" value="提交" >
      <input type="reset" value="清除">
      <br>
    </form>
    </body>
    </html>
      

  9.   

    对了,那个=="22"要改成equals("22");
      

  10.   


    又测试一下,突然想起,改了一下,把<form method="post" >改成<form method="post" action="posttoself.jsp">就好了,原来假如我通过地址栏输入http://localhost:8080/gb/posttoself.jsp?num=22来打开页面的话,
    在<form method="post" >的时候,它始终都是提交的num=22,5555555555555555555555555真是郁闷无比啊:(对了问大家一下,
    在用到
    if request.getParameter("num")的时候,都必须先判断
    if (request.getParameter("num")!=null)吗???
      

  11.   

    没问题,我在我这试很正常!<%@ page contentType="text/html; charset=GBK" %>
    <html>
    <head>
    <title>
    posttoself
    </title>
    </head>
    <body bgcolor="#ffffff">
    <h1>Post to self test</h1>
    <form method="post" >
    <br>请输入一个数字   :  <input name="num"><br>
    <input type="submit" name="Submit" value="提交" >
    <input type="reset" value="清除">
    <br>你输入的数字是<%=request.getParameter("num")%>
    <%
    if (request.getParameter("num")!=null)
    {
    if (request.getParameter("num").equals("22"))
    {out.write("恰好是你的年龄哦:)");
    }
    }
    %>
    <br>
    </form>
    </body>
    </html>