• Page directive must not have multiple occurrences of pageencoding


    转自:http://bbs.csdn.net/topics/210058964

    旁白

    今天将html代码改为jsp文件时,遇到报错,错误很低级,但是很深刻,特此将从csdn中查到的解决方案共享出来。

    正题

    在myeclipse中编写代码如下:
    q1.html:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>q1.html</title>
    
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="this is my page">
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        
        <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
    
      </head>
      
      <body>
      <FORM METHOD=POST ACTION="q2.jsp">
      请输入您的姓名:
      <INPUT TYPE=TEXT NAME="thename">
      <INPUT TYPE=SUBMIT VALUE="SUBMIT">
      </FORM>
      </body>
    </html>

    q2.jsp:

    <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1" 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 'q2.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">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    
      </head>
      
      <body>&nbsp; 
    
      <% String name=""; %>
      <%
      name=request.getParameter("thename");
      session.putValue("thename",name); 
      %>
      Your name : <%= name %>
      <p>
      <FORM METHOD=POST ACTION="q3.jsp">
      The food you like :
      <INPUT TYPE=TEXT NAME="food">
      <P>
      <INPUT TYPE=SUBMIT VALUE="SUBMIT">
      </P>
      </FORM>
      </body>
    </html>

    但在浏览器浏览浏览q2.jsp时却出现如下错误:

    HTTP Status 500 - 
    
    --------------------------------------------------------------------------------
    
    type Exception report
    
    message 
    
    description The server encountered an internal error () that prevented it from fulfilling this request.
    
    exception 
    
    org.apache.jasper.JasperException: /q2.jsp(1,1) Page directive must not have multiple occurrences of pageencoding
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:102)
    org.apache.jasper.compiler.Validator$DirectiveVisitor.visit(Validator.java:194)
    org.apache.jasper.compiler.Node$PageDirective.accept(Node.java:590)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
    org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2393)
    org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2399)
    org.apache.jasper.compiler.Node$Root.accept(Node.java:489)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
    org.apache.jasper.compiler.Validator.validate(Validator.java:1700)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:165)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:294)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:281)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    
    
    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.
    
    
    --------------------------------------------------------------------------------
    
    Apache Tomcat/6.0.16

    解决方案:

    pageEncoding="ISO-8859-1" pageEncoding="GBK"%
    不能指定多个pageEncoding

    (/q2.jsp(1,1) Page directive must not have multiple occurrences of pageencoding)

  • 相关阅读:
    了解一下下MFC基础中的基础
    【看书】浮点数陷阱
    [bbk4766] 第29集 第三章 Flashback Table 06
    [bbk4778] 第31集 第三章 Flashback Table 08
    [bbk4793] 第36集 第四章 Flashback Database 00
    [bbk4774] 第30集 第三章 Flashback Table 07
    [bbk4759] 第28集 第三章 Flashback Table 05
    [bbk4788] 第35集 第三章 Flashback Table 12
    [bbk4754] 第27集 第三章 Flashback Table 04
    [bbk4781] 第32集 第三章 Flashback Table 09
  • 原文地址:https://www.cnblogs.com/tv151579/p/3544397.html
Copyright © 2020-2023  润新知