JSP:Invalid character constant

代码:

<%
    out.print('abc');
%>

报错信息:

An error occurred at line: 27 in the jsp file: /tunps.com/emp_import.jsp
Invalid character constant
25: 
26: <%
27:     out.print('abc');
28: %>
29: 
30: 

原因:单引号修改为双引号,这是Java字符串,不是PHP!!!!!!!!!!!!!!!!!!!!!!!!!!= =#

Page directive must not have multiple occurrences of pageencoding at

org.apache.jasper.JasperException: /tunps/emp_import.jsp (line: 32, column: 1) Page directive must not have multiple occurrences of pageencoding 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:103) at org.apache.jasper.compiler.Validator$DirectiveVisitor.visit(Validator.java:196) at org.apache.jasper.compiler.Node$PageDirective.accept(Node.java:589) at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2392) at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2444) at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2450) at org.apache.jasper.compiler.Node$Root.accept(Node.java:474) at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2392) at org.apache.jasper.compiler.Validator.validateDirectives(Validator.java:1805) at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:196) 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 com.tunps.platform.util.filter.SystemValidationFilter.doFilter(SystemValidationFilter.java:75) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.tunps.platform.util.filter.ActionHelperFilter.doFilter(ActionHelperFilter.java:49) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.tunps.platform.util.antixss.AntiXssFilter.doFilter(AntiXssFilter.java:57) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.tunps.platform.util.filter.PerformanceAuditFilter.doFilter(PerformanceAuditFilter.java:39) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.tunps.platform.util.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:43) 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:956) 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.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) /tunps/emp_import.jsp (line: 32, column: 1) Page directive must not have multiple occurrences of pageencoding

原因是JSP页面出现了两个设置页面字符集的指令造成重复,去掉其中一个即可。

<%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>

<%@page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>

JSP服务器在传递url中文参数乱码

Tomcat服务器在传递url中文参数的时候默认使用的是ISO-8859-1编码,需要修改tomcat服务器配置文件server.xml,<Connector加上URIEncoding="UTF-8"

或者通过一下方式转码:

String zhongwen = new String("中文".getBytes("ISO-8859-1"),"UTF-8");