刚开始学JSP书上的一段小例子,运行出错,但是我不知道错在哪里
jsp_include.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<html>
<body>
<%@ include file="static.html" %>
<%//只是把文件包含进来%>
<a href="two.jsp">goto two</a><br>
this examples show include works
<jsp:include page="two.jsp" flush="true">
<jsp:param name="a1" value="<%=request.getParameter("name")%>" />
<jsp:param name="a2" value="<%=request.getParameter("password")%>" />
</jsp:include>
</body>
</html>
two.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" %>
举例说明include的工作原理:
<br>
this is a1=<%=request.getParameter("a1")%>
<br>
this is a2=<%=request.getParameter("a2")%>
<br>
<% out.println("hello from two.jsp");%>
static.html
<html>
<body>
<form method=post action="jsp_include.jsp">
<table>
<tr>
<td>please input your name:</td></tr>
<tr><td>
<input type=text name=name>
</td></tr>
<tr><td>input you password:</td>
<td>
<input type=text name=password>
</td>
</tr>
<tr>
<td>
<input type=submit value=login>
</td>
</tr>
</table>
</form>
</body>
</html>出错的地方应该是jsp_include.jsp中request调用处,我把value换成其他任意字符就好了,但是怎么改呢?

解决方案 »

  1.   

    <jsp:param name="a1" value="<%=request.getParameter("name")%>" />取掉=下面也是
      

  2.   

    <%=  ... %>表示打印
      

  3.   

    <%@ page contentType="text/html; charset=gb2312" language="java" %>
    <html>
    <body>
    <%@ include file="static.html" %>
    <%//只是把文件包含进来%>
    <a href="two.jsp">goto two</a><br>
    this examples show include works
    <%if(request.getParameter("name")!=null&&request.getParameter("password")!=null) {%>
    <jsp:include page="two.jsp" flush="true">
    <jsp:param name="a1" value='<%=request.getParameter("name")%>'  />
    <jsp:param name="a2" value='<%=request.getParameter("password")%>' />
    </jsp:include>
    <%} %>
    </body>
    </html>也可以将“”改为‘’
      

  4.   

    去掉了,但是 <%@ include file="static.html" %> 这句代码出错了 static.html 和 jsp_include.jsp 在同一目录下