在写标签的时候要养成好习惯
在写标签的时候要养成好习惯,尽量做到有始终,否则会出现问题!比如下面一个简单的JSP:
<body>
Welcome to our page !
<%if (request.getParameter("userName") == null) {%>
<jsp:forward page="HandleIt.jsp" >
<%} %>
<br>
Hello ${param.userName }
</body>
运行后出错:
SEVERE: Servlet.service() for servlet [jsp] in context with path [/BeerV1] threw exception [/Hello.jsp (line: 13, column: 0) Expecting “jsp:param” standard action with “name” and “value” attributes] with root cause
org.apache.jasper.JasperException: /Hello.jsp (line: 13, column: 0) Expecting “jsp:param” standard action with “name” and “value” attributes
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:443)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:89)
at org.apache.jasper.compiler.Parser.parseParam(Parser.java:809)
at org.apache.jasper.compiler.Parser.parseBody(Parser.java:1671)
at org.apache.jasper.compiler.Parser.parseOptionalBody(Parser.java:986)
at org.apache.jasper.compiler.Parser.parseForward(Parser.java:850)
at org.apache.jasper.compiler.Parser.parseStandardAction(Parser.java:1102)
at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1450)
at org.apache.jasper.compiler.Parser.parse(Parser.java:138)
at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:242)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:199)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:374)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:341)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:662)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:364)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocolAbstractConnectionHandler.process(AbstractProtocol.java:620)atorg.apache.tomcat.util.net.JIoEndpointSocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutorWorker.run(ThreadPoolExecutor.java:617)atorg.apache.tomcat.util.threads.TaskThreadWrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
问题就在于jsp:forward标签没有显示结束!应该像下面这样,所以尽量避免这样的东西。
<%if (request.getParameter("userName") == null) {%>
<jsp:forward page="HandleIt.jsp" />
<%} %>