zoukankan      html  css  js  c++  java
  • JSP

    JSP表达式<%=表达式%>

    scriptlet<% java code%>

    1. jsp 方法和变量:

    <%! 方法或者域%>

    //定义的是全局的方法和成员变量;如:

    <%! private int a=9;

      private String fun1(){

      return ("<H2>HAHA<H2>");  

    }

    %>

    在编译的.java文件中为:全局变量和方法


    private int x=8;
    private String fun1(){
    return ("<H2>haha<H2>");
    }

    而<% int x = 8;%>//这种声明的是局部变量,被插入到_jspservice方法中.

    2. 使用预定义变量:

    在servlet中 doGet()方法:

    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
    resp.setContentType("text/html");
    resp.setCharacterEncoding("utf-8");
    PrintWriter out = resp.getWriter();
    HttpSession session = req.getSession();
    out.println("seesion is new: "+session.isNew()+"<br>");
    out.println("sessionID :"+session.getId()+"<br>");
    session.setAttribute("addr", "上海市。黄浦区");

    );
    }

    servlet API告诉doGet参数类型,可以获取会话对象和输出所需的方法,而JSP将方法名从doGet改为了_JSPService,并使用JspWrite替代PrintWriter 。

    _JSPService中自定义了8个局部变量(可用变量:requst,response,out,session,application,config,pagecontext,page),称为“隐含对象”。因此,如果你编写的代码不属于_JSPService,则不能使用这些变量。还要一个附加变量exception仅仅在错误页面中才可以用。

  • 相关阅读:
    SQL查询,点击三维图层,查询属性信息
    title标签的使用
    idea快捷键大全
    intellij idea创建第一个动态web项目
    IDEA设置为黑色背景(今天开始使用idea,并记录点滴,记录坑)
    Eclipse导出Jar包(包含外部包)
    获取当前系统时间
    JS实现的ajax和同源策略
    缓存
    Restful Framework (四)
  • 原文地址:https://www.cnblogs.com/daxiong225/p/4775919.html
Copyright © 2011-2022 走看看