下面3段代码是书上的小例子,问题就在以下jsp_include.jsp代码段中。
<jsp:param name="a1" value='<%=request.getParameter("name")%>' />
<jsp:param name="a2" value='<%=request.getParameter("password")%>' />

这两句代码中,现在value='...',但是书上此处用的是"..."后来改的,才能正确运行。所以我就不明白,这单引号''和双引号""有什么区别,为什么变了''才能使下面3段代码正确运行?
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>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>two.jsp
<%@ page language="java" contentType="text/html; charset=gb2312"
    pageEncoding="gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<br>
this is a1=<%=request.getParameter("a1")%>
<br>
this is a2=<%=request.getParameter("a2")%>
<br>
<% out.println("hello from two.jsp");%>
</body>
</html>

解决方案 »

  1.   

    我这么理解:
    双引号里面的字段会经过编译器解释,然后再当作HTML代码输出。 
    单引号里面的不进行解释,直接输出。
      

  2.   

    感谢楼上的,但是这样的Scriptlet代码段 <%=request.getParameter("name")%> 不经过编译也能行的通吗?
      

  3.   

    <jsp:param name="a1" value=" <%=request.getParameter("name")%>" /> 
    就是说你如果是这样,那么value=" <%=request.getParameter("这就是一对
    ")%>" 这是另一对
    是这么匹配的,所以你要改成单引号
      

  4.   

    就进匹配就是:
    看下面的一下行代码:
    <jsp:param name="a2" value=" <%=request.getParameter("password")%>" /> 
    用的都是双引号的话,就会把红色的代码匹配在一起,
    下面的会把password匹配在一起,
    <jsp:param name="a2" value=' <%=request.getParameter("password")%>' />