内置对象

本文详细介绍了JSP中的九种内置对象,包括request、response、out等,并通过实例展示了这些对象如何在JSP页面中被预定义及使用。此外,还深入探讨了config对象的应用场景及其配置方式。

                                                            jsp的内置对象使用探究                     
内置对象是不需要声明(其实已经处理过被声明了,只是你自己编写程序是不用特地声明而已),直接可以在JSP中使用的对象,JSP有以下几种内置对象:
jsp九种内置对象:request, reponse, out, session, application, config, pagecontext, page, exception
观察自己所写的jsp文件被servlet容器器编译后生成的servlet源文件。发现所谓的jsp内置的对象,其实只是被预先定义好了而已,美其名曰内置对象。你才可以直接使用。

package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.util.*;
import com.webstore.user.*;

public final class Login_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();

  private static java.util.List _jspx_dependants;

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.AnnotationProcessor _jsp_annotationprocessor;

  public Object getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());
  }

  public void _jspDestroy() {
  }
  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {
                                         //编译成servlet后添加了很多代码,加进去了相应的内置对象。


    PageContext pageContext = null;      //以下就是在你用之前就已事先定义好的那些对象,才导致你可以在jsp里可以直接使用。   
    HttpSession session = null;          //而request和response对象是由服务器生成的。他将这两个对象传进来,然后回调          
    ServletContext application = null;   // _jspService()方法。
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;
try {
      response.setContentType("text/html;charset=GBK");
      pageContext = _jspxFactory.getPageContext(this, request, response,
                              null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\r\n");
      out.write("<html>\r\n");
      out.write("\t<head>\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\t\t<title>自服务系统</title>\r\n");
      out.write("\r\n");
      out.write("\t\t<meta http-equiv=\"pragma\" content=\"no-cache\">\r\n");
      out.write("\t\t<meta http-equiv=\"cache-control\" content=\"no-cache\">\r\n");
      out.write("\t\t<meta http-equiv=\"expires\" content=\"0\">\r\n");
      out.write("\t\t<meta http-equiv=\"keywords\" content=\"keyword1,keyword2,keyword3\">\r\n");
      out.write("\t\t<meta http-equiv=\"description\" content=\"This is my page\">\r\n");
      out.write("\t\t<!--\r\n");
      out.write("\t<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\">\r\n");
      out.write("\t-->\r\n");
      out.write("\r\n");
      out.write("\t</head>\r\n");
      out.write("\r\n");
      out.write("\t<body>\r\n");
      out.write("\t\t<center>\r\n");
      out.write("\t\t\t欢迎您:\r\n");
      out.write("\t\t\t");
      out.print(username);
      out.write("\r\n");
      out.write("\t\t\t<br>\r\n");
      out.write("\t\t\t<a href=\"UserModify.jsp\">修改我的信息</a>\r\n");
      out.write("\t\t\t<br>\r\n");
      out.write("\t\t\t\r\n");
      out.write("\t\t\t<br>\r\n");
      out.write("\t\t\t<a href=\"MyOrders.jsp\">浏览以往订单</a>\r\n");
      out.write("\t\t</center>\r\n");
      out.write("\t</body>\r\n");
      out.write("</html>\r\n");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try { out.clearBuffer(); } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
 


分析:HttpJspBase继承了javax.servlet.http.HttpServlet

config对象的使用
作用范围就当前页面,被包含到别的页面无效.jsp的config对象作用不大,在servlet中作用比较大.

<%@ page language="java" contentType="text/html; charset=utf-8"
  pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>meg.jsp</title>
  </head>
  <body>
    <table align="center" border="0" cellPadding="0" cellSpacing="0"
      width="730">
      <tr>
        <td>
          <div align="center">
            <br>
            客户服务信箱:
            <%=config.getInitParameter("email")%>
            客户服务热线:
            <%=config.getInitParameter("phone")%>
            <br>
            客户服务 QQ:
            <%=config.getInitParameter("qq")%>
            <br>
          </div>
        </td>
      </tr>
    </table>
  </body>
</html>


在web.xml的</web-app>前插入
<!-- config -->
    <servlet>
     <servlet-name>admin</servlet-name>
     <jsp-file>/config.jsp</jsp-file>
     <init-param>
        <param-name>email</param-name>
        <param-value>service@abc.com</param-value>
     </init-param>
     <init-param>
        <param-name>phone</param-name>
        <param-value>0411-12345678</param-value>
     </init-param>
     <init-param>
        <param-name>qq</param-name>
        <param-value>88888中文呢</param-value>
     </init-param>
    </servlet>
    <servlet-mapping>
     <servlet-name>admin</servlet-name>
     <url-pattern>/config.jsp</url-pattern>
    </servlet-mapping>
<!-- end config -->
 
【四旋翼无人机】具备螺旋桨倾斜机构的全驱动四旋翼无人机:建模与控制研究(Matlab代码、Simulink仿真实现)内容概要:本文围绕具备螺旋桨倾斜机构的全驱动四旋翼无人机展开研究,重点探讨其系统建模与控制策略,结合Matlab代码与Simulink仿真实现。文章详细分析了无人机的动力学模型,特别是引入螺旋桨倾斜机构后带来的全驱动特性,使其在姿态与位置控制上具备更强的机动性与自由度。研究涵盖了非线性系统建模、控制器设计(如PID、MPC、非线性控制等)、仿真验证及动态响应分析,旨在提升无人机在复杂环境下的稳定性和控制精度。同时,文中提供的Matlab/Simulink资源便于读者复现实验并进一步优化控制算法。; 适合人群:具备一定控制理论基础和Matlab/Simulink仿真经验的研究生、科研人员及无人机控制系统开发工程师,尤其适合从事飞行器建模与先进控制算法研究的专业人员。; 使用场景及目标:①用于全驱动四旋翼无人机的动力学建模与仿真平台搭建;②研究先进控制算法(如模型预测控制、非线性控制)在无人机系统中的应用;③支持科研论文复现、课程设计或毕业课题开发,推动无人机高机动控制技术的研究进展。; 阅读建议:建议读者结合文档提供的Matlab代码与Simulink模型,逐步实现建模与控制算法,重点关注坐标系定义、力矩分配逻辑及控制闭环的设计细节,同时可通过修改参数和添加扰动来验证系统的鲁棒性与适应性。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值