<%@ page language="a"e="/html; charset=UTF-8"eEncoding="UTF-8">
<%@ page import="a.util.*"
JSP警告实例
body { font-family: Arial, sans-serif; margin: 40px; }
.warning {
background-color: #fff3cd;
border: 1px solid #ffeaa7;
padding: 15px;
margin: 10px 0;
border-radius: 5px;
color: #856404;
}
.error {
background-color: #f8d7da;
border: 1px solid #f5c6cb;
padding: 15px;
margin: 10px 0;
border-radius: 5px;
color: #721c24;
}
常见JSP警告类型演示
<%-- 1. 隐式对象使用警告 --%>
<%
// 模拟pageContext隐式对象使用
pageContext.setAttribute("testAttr"测试值" String value = (String)pageContext.getAttribute("Attr" %>
页面属性值: <%= value %>
<%-- 2. 脚本元素使用警告 --%>
<%
// 传统的脚本元素使用(不推荐)
Date now = new Date();
String userAgent = request.getHeader("User-Agent" %>
当前时间: <%= now %>
浏览器信息: <%= userAgent %>
<%-- 3. 作用域管理警告 --%>
<%
// 在不同作用域设置相同属性名
pageContext.setAttribute("message" "作用域消息" request.setAttribute("e"请求作用域消息" session.setAttribute("message" "作用域消息" application.setAttribute("e"应用作用域消息" %>
页面作用域: <%= pageContext.getAttribute("message" %>
请求作用域: <%= request.getAttribute("message" %>
<%-- 4. 异常处理警告 --%>
<%
try {
// 模拟可能产生异常的代码
String nullStr = null;
int length = nullStr.length(); // 这里会产生NullPointerException
} catch (Exception e) {
out.println("捕获到异常: " e.getMessage());
}
%>
<%-- 5. 编码问题警告 --%>
<%
// 模拟参数接收(可能存在的编码问题)
String param = request.getParameter("Param" if (param != null) {
// 未进行编码处理的参数输出
out.println("接收参数: " + param);
}
%>
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"