jsp:forward使用时遇到:Expecting "jsp:param" standard action with "name" and "value" attributes 错误

今天在测试JSP中的<jsp:forward>指令时遇到了以下错误提示:

org.apache.jasper.JasperException: /index.jsp (line: 24, column: 4) Expecting "jsp:param" standard action with "name" and "value" attributes
	org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
	org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:408)
	org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:89)
	org.apache.jasper.compiler.Parser.parseParam(Parser.java:825)
	org.apache.jasper.compiler.Parser.parseBody(Parser.java:1672)
	org.apache.jasper.compiler.Parser.parseOptionalBody(Parser.java:1002)
	org.apache.jasper.compiler.Parser.parseForward(Parser.java:866)
	org.apache.jasper.compiler.Parser.parseStandardAction(Parser.java:1118)
	org.apache.jasper.compiler.Parser.parseElements(Parser.java:1451)
	org.apache.jasper.compiler.Parser.parse(Parser.java:138)
	org.apache.jasper.compiler.ParserController.doParse(ParserController.java:242)
	org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
	org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

JSP页面代码为:

<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
  </head>
  
  <body>
  <%@ include file="top.jsp" %>
    <!-- <a href="./errorTest.jsp">错误测试</a> -->
    <jsp:forward page="./errorTest.jsp">        (这处的<jsp:forward></jsp:forward>标签对不能跨行)
    </jsp:forward>
    <br>
  </body>
</html>

经查发现,导致出现该错误的原因就是代码中<jsp:forward page="./errorTest.jsp"></jsp:forward>这对标签跨行了;当<jsp:forward></jsp:forward>标签对没进行传参时(即没有<jsp:param>子标签时),不能跨行;反之,进行传参时(有<jsp:param>子标签)可以跨行,例如:

    <jsp:forward page="./errorTest.jsp">
    <jsp:param value="Hello!" name="param1"/>
    <jsp:param value="hi!" name="param2"/>
    </jsp:forward>

(备注:本人的测试环境:MyEclipse2014、JDK1.6、Tomcat7.0)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值