org.apache.jasper.JasperException: - Page directive must not have multiple occurrences of pageencoding

时间:2021-04-27 19:44:09

最近写jsp遇到一系列的低级错误,记录下来权当前车之鉴吧。

错误提示:

SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: /jsp04/Zj04_sj_test1_1.jsp(2,1) Page directive must not have multiple occurrences of pageencoding

程序代码如下:

 <%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page language="java" import="jsp04.*" pageEncoding="gbk"%>
<%@ page import="javax.servlet.jsp.jstl.sql.Result;"%>
<%
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>民意调查</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>
<br>
在校大学生是否适合做兼职 <br>
<br>
<%
//构造sql语句,取出调查
String sql="select * from surveyItem where surveyID=1";
Object params[]={};
//获取调查项列表
Result result=DBHelp.runSelectSql(sql,params);
Map[] rows=result.getRows();
//循环访问每一个调查项
for(int i=0;i<rows.length;i++){
//得到调查项目的ID
int id=Integer.parseInt(rows[i].get("id").toString());
//得到调查项
String item=rows[i].get("item").toString();
%>
<input type="radio" name="radsurver" value="<%=id %>"><%=item %>
<%
}
%><br>
<input type="submie" name="Submit" value="提交">
<input type="reset" name="Submit2" value="重置">
</body>
</html>
首先,org.apache.jasper.JasperException 中的JasperException
这个异常时jsp引擎解析jsp页面生成servlet时产生的,故错误是在转译阶段,应该是页面的语法有问题,而不是执行阶段出错
然后,检查一下配置,发现页面编码设置了两次,虽然是一样的编码,但还是不被允许的
最后,第二行改为:
  
<%@ page import="jsp04.*" %>

OK  !