2021第一周总结一些点

封装小程序utils/request.js```

const BASE_URL = 'https://xcx.duolalive.com/apixcx/';
const BASE_METHOD = 'POST';
const DATA_TYPE = 'json';
const TOAST_DURATION = 1500;
let header = {};

//抽象出处理错误信息的公共方法
const handleErrorMsg = (errMsg) => {
  wx.showModal({
    title: '提示',
    content: errMsg,
    showCancel: false,
  });
}

function request(url, params = {}, showMsg = false) {
  // 绑定手机需要携带cookie
  if (params.regist) {
    header['cookie'] = wx.getStorageSync("SESSION_ID")
  }
  return new Promise((resolve, reject) => {
    wx.showLoading({
      title: '加载中'
    });
    wx.request({
      data: params,
      url: BASE_URL + url,
      method: params.method ? params.method : BASE_METHOD,
      dataType: DATA_TYPE,
      header: {
        ...header,
        "content-type": params.method ? "application/json" : "application/x-www-form-urlencoded",
      },
      success: ({
        data,
        statusCode,
        errMsg,
        header
      }) => {
        let errStr = '';
        wx.hideLoading();
        let _data = JSON.parse(JSON.stringify(data))
        const { code, msg } = _data
        // 发送验证码需要携带session_id
        if (params.send_code) {
          wx.removeStorageSync('SESSION_ID')
          wx.nextTick(() => {
            wx.setStorageSync("SESSION_ID", header["Set-Cookie"]);
          })
        }
        //增加代码的健壮性
        if (statusCode === 200) {
          if (Number(code) !== 0) { // 接口出错
            errStr = msg
          } else {
            if (!showMsg) {
              return resolve(_data);
            }
            // 展示操作提示
            wx.showToast({
              duration: TOAST_DURATION,
              title: '操作成功',
              icon: 'success',
              complete: () => resolve(_data),
            });
            return;
          }
        } else {
          errStr = errMsg // 小程序方出错
        }
        if (statusCode !== 200 || code !== 0) {
          if (code !== -100) {
            handleErrorMsg(errStr)
          }
          reject(data)
        }
      },
      fail: ({
        statusCode,
        errMsg
      }) => {
        wx.hideLoading();
        handleErrorMsg(`${statusCode}: ${errMsg}`)
        reject({
          statusCode,
          errMsg
        });
      },
    });
  })
}
export default request

获取手机验证码方法

接口://https://xcx.duolalive.com/apixcx/wx_login.php
测试数据://phone:17722486332;send_code: 1

``>

    // 60秒后重新获取验证码
    this.login(true);
    inter = setInterval(function () {
      this.setData({
        smsFlag: true,
        sendColor: '#cccccc',
        sendTime: this.data.snsMsgWait + 's后重发',
        snsMsgWait: this.data.snsMsgWait - 1
      });
      if (this.data.snsMsgWait < 0) {
        clearInterval(inter)
        this.setData({
          sendTime: '获取验证码',
          snsMsgWait: 60,
          smsFlag: false
        });
      }
    }.bind(this), 1000);     //注意定时器中的this
  },

java搭建本地服务器

tomcat服务器

2021第一周总结一些点_第1张图片

  1. conf/server核心配置修改一下配置,可以修改服务器默认端口和某人主机名
  2. 修改后的默认主机名,要在计算机C:window\System32\deivers\etc\host配置文件中配置
//tomcat默认端口号8080;mysql:3306;http:80;https:443

//默认主机名为localhost->127.0.0.1
//默认网址应用存放位置:webapps

  1. idea中配置tomcat2021第一周总结一些点_第2张图片
    2021第一周总结一些点_第3张图片

Maven配置

  1. 配置环境变量,和Java配置环境变量一样,cmd下mvn -version出现maven版本表示配置成功2021第一周总结一些点_第4张图片
  2. 修改镜像源为阿里云镜像源:conf/setting.xml/mirror

    nexus-aliyun
    *,!jeecg,!jeecg-snapshots
    Nexus aliyun
    http://maven.aliyun.com/nexus/content/groups/public
 
  1. 新建文帝仓储
G:\apache-maven-3.6.3\maven-repo
  1. 修改web.xml为最新代码



  1. 完善maven的结构 main/java&&resource文件包

servlet程序

  1. 编写普通类继承HttpServlet基类
package com.huang.cookies;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class SessionDemo2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        resp.setCharacterEncoding("utf-8");
        req.setCharacterEncoding("utf-8");
        HttpSession session = req.getSession();
        String name = (String) session.getAttribute("name");
//        null;大神
        System.out.println(name);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
  1. 编写web.xml中配置servlet映射

     getSession
     com.huang.cookies.SessionDemo2
 
 
     getSession
     /getSession
 

你可能感兴趣的:(javaweb,javascript,java)