当前时间:<%= new java.util.Date() %>
``` #### 2. JSP三种脚本元素 | 类型 | 语法 | 说明 | | ------ | --------------- | ------------------ | | 声明 | `<%! 代码 %>` | 定义成员变量和方法 | | 脚本 | `<% 代码 %>` | 执行Java代码 | | 表达式 | `<%= 表达式 %>` | 输出结果 | ```jsp <%! // 声明:成员变量 private int count = 0; // 声明:方法 public String getInfo() { return "Hello"; } %> <% // 脚本:执行代码 count++; String name = request.getParameter("name"); %>访问次数:<%= count %>
姓名:<%= name %>
``` #### 3. JSP内置对象(9个) | 对象 | 类型 | 说明 | | ----------- | ------------------- | --------------------- | | request | HttpServletRequest | 请求对象 | | response | HttpServletResponse | 响应对象 | | out | JspWriter | 输出对象 | | session | HttpSession | 会话对象 | | application | ServletContext | 全局对象 | | pageContext | PageContext | 页面上下文 | | config | ServletConfig | 配置对象 | | page | Object | 当前页面对象 | | exception | Throwable | 异常对象(errorPage) | ```jsp <% // 使用内置对象 request.getParameter("name"); response.setContentType("text/html"); out.print("输出"); session.setAttribute("user", "张三"); application.setAttribute("count", 100); %> ``` #### 4. JSP指令 ```jsp <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page import="java.util.*, java.sql.*" %> <%@ page errorPage="error.jsp" %> <%@ page isErrorPage="true" %> <%@ include file="header.jsp" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> ``` #### 5. JSP四大作用域 | 作用域 | 对象 | 说明 | 生命周期 | | ----------- | ----------- | -------- | ---------------- | | page | pageContext | 当前页面 | 请求结束 | | request | request | 一次请求 | 请求结束 | | session | session | 一次会话 | 浏览器关闭或超时 | | application | application | 整个应用 | 服务器关闭 | ```jsp <% pageContext.setAttribute("pageData", "页面数据"); request.setAttribute("reqData", "请求数据"); session.setAttribute("sessionData", "会话数据"); application.setAttribute("appData", "应用数据"); %> ``` --- ### 七、Session和Cookie #### 1. Cookie(客户端存储) ```java @WebServlet("/cookie") public class CookieServlet extends HttpServlet { protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // 创建Cookie Cookie cookie = new Cookie("username", "张三"); cookie.setMaxAge(60 * 60); // 有效期1小时(秒) cookie.setPath("/"); // 有效路径 resp.addCookie(cookie); // 获取Cookie Cookie[] cookies = req.getCookies(); if (cookies != null) { for (Cookie c : cookies) { if ("username".equals(c.getName())) { String value = c.getValue(); } } } // 删除Cookie cookie.setMaxAge(0); resp.addCookie(cookie); } } ``` #### 2. Session(服务端存储) ```java @WebServlet("/session") public class SessionServlet extends HttpServlet { protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // 获取Session(true:不存在则创建) HttpSession session = req.getSession(); // 设置属性 session.setAttribute("userId", 1001); session.setAttribute("username", "张三"); // 获取属性 String username = (String) session.getAttribute("username"); // 移除属性 session.removeAttribute("username"); // 设置超时时间(秒) session.setMaxInactiveInterval(1800); // 30分钟 // 手动销毁 session.invalidate(); // 获取Session ID String sessionId = session.getId(); } } ``` #### 3. Cookie vs Session | 对比 | Cookie | Session | | -------- | ------------------ | -------------------- | | 存储位置 | 客户端(浏览器) | 服务端 | | 存储大小 | 4KB左右 | 无限制(受内存限制) | | 安全性 | 低(可被篡改) | 高 | | 生命周期 | 可设置 | 超时或手动销毁 | | 适用场景 | 记住密码、自动登录 | 登录状态、验证码 | #### 4. 登录案例 ```java @WebServlet("/login") public class LoginServlet extends HttpServlet { protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("UTF-8"); String username = req.getParameter("username"); String password = req.getParameter("password"); // 模拟验证 if ("admin".equals(username) && "123".equals(password)) { // 登录成功,保存Session HttpSession session = req.getSession(); session.setAttribute("user", username); // 记住密码(Cookie) String remember = req.getParameter("remember"); if ("on".equals(remember)) { Cookie cookie = new Cookie("username", username); cookie.setMaxAge(7 * 24 * 60 * 60); resp.addCookie(cookie); } resp.sendRedirect(req.getContextPath() + "/index.jsp"); } else { req.setAttribute("error", "用户名或密码错误"); req.getRequestDispatcher("/login.jsp").forward(req, resp); } } } ``` --- ### 八、过滤器 #### 1. 什么是Filter? Filter用于拦截请求和响应,在Servlet执行前后进行处理。 **常见应用:** - 编码过滤(解决乱码) - 登录验证 - 日志记录 - 权限控制 #### 2. 创建Filter ```java @WebFilter("/*") // 拦截所有请求 public class EncodingFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { System.out.println("过滤器初始化"); } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // 前置处理 request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); System.out.println("请求到达前"); // 放行(继续执行下一个过滤器或Servlet) chain.doFilter(request, response); // 后置处理 System.out.println("响应返回后"); } @Override public void destroy() { System.out.println("过滤器销毁"); } } ``` #### 3. 登录验证Filter ```java @WebFilter({"/user/*", "/admin/*"}) // 拦截需要登录的路径 public class LoginFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse resp = (HttpServletResponse) response; HttpSession session = req.getSession(); Object user = session.getAttribute("user"); if (user == null) { // 未登录,跳转到登录页 resp.sendRedirect(req.getContextPath() + "/login.jsp"); } else { // 已登录,放行 chain.doFilter(request, response); } } } ``` --- ### 九、监听器 #### 1. 什么是Listener? Listener监听Web应用中的事件,在特定时机执行代码。 **监听器类型:** | 类型 | 接口 | 触发时机 | | ---------- | ---------------------- | ---------------- | | 上下文监听 | ServletContextListener | 服务器启动/关闭 | | 会话监听 | HttpSessionListener | Session创建/销毁 | | 请求监听 | ServletRequestListener | 请求开始/结束 | | 属性监听 | 对应AttributeListener | 属性增删改 | --- ### 十、MVC模式 #### 1. 什么是MVC? | 组件 | 全称 | 说明 | 技术 | | ---- | ---------- | -------- | ---------------------- | | M | Model | 数据模型 | JavaBean、Service、DAO | | V | View | 视图 | JSP、HTML | | C | Controller | 控制器 | Servlet | **工作流程:** ``` 浏览器 → 控制器(Servlet) → 调用Model(Service/DAO) → 获取数据 → 转发到View(JSP) → 响应 ``` --- # 股票知识 ## 超级云脑 --- ### 一、投资决策的三大难题 在股票投资中,我们经常面临三个核心问题: | 问题编号 | 核心问题 | 具体描述 | | -------- | -------------- | -------------------------------------- | | 问题一 | 能持有吗? | 股票买完后,不知道能不能继续持有 | | 问题二 | 有风险吗? | 股票在上涨过程中,不知道风险有多大 | | 问题三 | 主力什么态度? | 股票遇到压力时,不知道主力是在买还是卖 | **解决方案:** 利用人工智能(AI)分析金融大数据,用AI解决决策难题。 --- ### 二、超级云脑是什么? **定义:** 超级云脑是将人工智能与金融股票领域融合的工具,能够快速处理大量金融数据,为投资者提供行情分析和预判。 **三大优势:** | 优势 | 说明 | | ---------- | -------------------------------------- | | 处理速度快 | 瞬间处理大量金融数据 | | 能赚钱 | 通过大数据分析帮助投资者获利 | | 天然匹配 | 金融市场本身就是大数据市场,AI正好适合 | --- ### 三、核心功能一:六色罗盘(判断安全与风险) 六色罗盘是一个从**绿色(安全)到红色(风险)** 的图示工具。 | 区域 | 含义 | 操作建议 | | -------- | ------ | ------------------ | | 绿色区域 | 安全区 | 相对安全,可持有 | | 红色区域 | 风险区 | 注意风险,考虑减仓 | **罗盘细分:** - 强撑强压区 - 弱撑强压区 - 强撑中压区 - 弱撑中压区 - 强撑弱压区 - 弱撑弱压区 > **使用方法:** 看指针指向哪个区域,绿色安全,红色危险。 --- ### 四、核心功能二:技术指标分析(判断压力与支撑) 技术指标分析告诉我们以下关键信息: | 指标 | 含义 | 示例数据 | | ---------------- | ---------------------------- | ------------------ | | 中长期筹码成本价 | 大多数持股者的平均成本 | 1.648 | | 短期资金成本价 | 近期买入资金的平均成本 | 1.589 | | 压力位 | 股价涨到这个位置可能遇到阻力 | 3.084 | | 支撑位 | 股价跌到这个位置可能获得支撑 | 0.505 | | 趋势 | 股价的长期运行方向 | 中长期处于上升趋势 | **关键判断:** - 压力强度大 → 需要放巨量才能突破 - 获利筹码增加 + 获利了结意愿不明显 → 筹码稳定性好 --- ### 五、核心功能三:资金流向(判断主力态度) | 观察点 | 判断依据 | 结论 | | ---------------- | ---------------- | ---------- | | 庄家在买还是卖? | 当前多头资金占优 | 主力在买 | | 资金是否持续? | 多头资金持续流入 | 资金在流进 | > **结论:** 当前市场多头资金占优,且持续流入,整体资金在流进。 --- ### 六、超级云脑四大分析维度 | 维度 | 要回答的问题 | 对应功能 | | -------- | ---------------------- | ------------ | | 安全性 | 我的股票安全吗? | 六色罗盘 | | 压力点 | 涨到什么价位要注意? | 技术指标分析 | | 主力态度 | 主力在买还是卖? | 资金流向分析 | | 资金动向 | 市场资金流入还是流出? | 资金流向分析 | --- ### 七、今日小结 | 知识点 | 掌握要求 | | ------------- | ---------------------------------------- | | 三大难题 | 能说出买完后能否持有、有无风险、主力态度 | | 超级云脑 | 能说出它是AI+金融的分析工具 | | 六色罗盘 | 绿色安全、红色风险 | | 压力位/支撑位 | 压力位是上涨阻力,支撑位是下跌支撑 | | 资金流向 | 多头占优+持续流入=看好 | ###