IDEA(2020版)实现JSP隐式对象

查看全文:IDEA(2020版)实现JSP隐式对象 – 每天进步一点点

 


 

一、out对象

在JSP页面中,经常需要向课后端发送文本内容。向课后端发送文本内容可以使用out对象实现。

右击web,选择New—>JSP/JSPX,名字为out.jsp

代码参考如下:

<%@ page contentType="text/html;charset=UTF-8" language="java" buffer="0kb" %>
<html>
<head>
    <title>Insert title here</title>
</head>
<body>
<%
    out.println("first line<br />");
    response.getWriter().println("second line<br />");

</body>
</html>

在浏览器里输入jsp的地址

http://localhost:8080/chapter06/out.jsp

运行后结果如下:

二、pageContext对象

右击web文件夹,选择New—>JSP/JSPX,名字为pageContext.jsp

代码参考如下:

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<html>
<head>
    <title>pageContext</title>
</head>
<body>
<%
    //获取request对象
    HttpServletRequest req = (HttpServletRequest) pageContext
            .getRequest();
    //设置page范围内属性
    pageContext.setAttribute("str", "Java",pageContext.PAGE_SCOPE);
    //设置request范围内属性
    req.setAttribute("str", "Java Web");
    //获得的page范围属性
    String str1 = (String)pageContext.getAttribute("str",
            pageContext.PAGE_SCOPE);
    //获得的request范围属性
    String str2 = (String)pageContext.getAttribute("str",
            pageContext.REQUEST_SCOPE);

<%="page范围:"+str1 %><br />
<%="request范围:"+str2 %><br />
</body>
</html>

在浏览器中输入下面的地址

http://localhost:8080/chapter06/pageContext.jsp

运行tomcat后,运行结果如下:

三、exception对象

在JSP页面中,经常需要处理一些异常信息,处理异常信息可以通过exception对象实现。

右击web文件夹,选择New—>JSP/JSPX,名字为exception.jsp

参考代码如下:

 

 

 


 

查看全文:IDEA(2020版)实现JSP隐式对象 – 每天进步一点点

posted on 2025-12-04 17:15  longkui  阅读(1)  评论(0)    收藏  举报

导航