最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue調(diào)用后端java接口的實(shí)例代碼

 更新時(shí)間:2019年10月28日 17:18:56   作者:2heal  
今天小編就為大家分享一篇Vue調(diào)用后端java接口的實(shí)例代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

前段時(shí)間 做了個(gè)學(xué)校的春萌項(xiàng)目,其中用到vue連接后端java接口。

先上后端接口代碼:

package controller;

import net.sf.json.JSONObject;
import util.DBUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

@WebServlet(name = "login",urlPatterns = "/login")
public class login extends HttpServlet {
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession session = request.getSession(true);
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    DBUtil dbUtil = new DBUtil();
    Connection connection = dbUtil.getConnection();
    PreparedStatement preparedStatement;
    ResultSet rs;
    String psw="";
    String sql = "select password from `user` where username=?";
    try {
      preparedStatement = connection.prepareStatement(sql);
      preparedStatement.setInt(1,Integer.parseInt(username));
      rs = preparedStatement.executeQuery();
      while (rs.next()){
        psw = rs.getString("password");
      }
    }
    catch (Exception e){
      e.printStackTrace();
    }
    if (password.equals(psw)){
      session.setAttribute("username",username);
      response.getWriter().print("true");
    }
    else
    response.getWriter().print("false");
  }

  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

  }
}

前端調(diào)用:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Login</title>
  <script src="node_modules/vue/dist/vue.js"></script>
  <!--axios基于promise-->
  <script src="node_modules/axios/dist/axios.js"></script>
  <script src="login.js"></script>
  <script src="https://cdn.bootcss.com/vue-resource/1.5.1/vue-resource.min.js"></script>
  <link rel="stylesheet" href="login.css" rel="external nofollow" >
</head>
<body>
<div class="login_interface" id="interface_height">
  <img src="ic_login_logo.png" alt="" class="login_logo">
  <span id="login_head">智慧圖書管理平臺(tái)</span>
  <div class="login_input">
    <img src="ic_login_number.png" alt="" class="login_number">
    <input type="text" value="請(qǐng)輸入賬號(hào)" id="input_number" v-model="username">
  </div>
  <div class="login_input" id="add_top">
    <img src="ic_login_password.png" alt="" class="login_number">
    <input type="text" value="請(qǐng)輸入密碼" id="input_password" v-model="password">
  </div>
  <button class="login_unselected" id="tick"></button>
  <span id="remember_password">記住密碼</span>
  <button id="registered_now"><a href=""><span style=" rel="external nofollow" color: grey">立即注冊(cè)</span></a></button>
  <button id="login" @click="login()">登錄</button>
</div>
<script>
  new Vue({
    el:'#interface_height',
    data:{
      username:'',
      password:''
    },
    methods:{
      login:function () {
        this.$http.post('login',{username:this.username,password:this.password},{emulateJSON:true}).then(function(res){
          console.log(res.data);
          window.location.href = 'index.html';
        },function(res){
          console.log(res.status);
        });
      }
    },
    created:function(){
    }
  })
</script>
</body>
</html>

以上這篇Vue調(diào)用后端java接口的實(shí)例代碼就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Nuxt的動(dòng)態(tài)路由和參數(shù)校驗(yàn)操作

    Nuxt的動(dòng)態(tài)路由和參數(shù)校驗(yàn)操作

    這篇文章主要介紹了Nuxt的動(dòng)態(tài)路由和參數(shù)校驗(yàn)操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • 談?wù)刅ue中的nextTick

    談?wù)刅ue中的nextTick

    Vue.nextTick是Vue官方給我們提供的一個(gè)API(方法),作用是在下次DOM更新循環(huán)結(jié)束之后執(zhí)行延遲回調(diào)。在修改數(shù)據(jù)之后立即使用這個(gè)方法,獲取更新后的DOM
    2021-04-04
  • UniApp中實(shí)現(xiàn)類似錨點(diǎn)定位滾動(dòng)效果

    UniApp中實(shí)現(xiàn)類似錨點(diǎn)定位滾動(dòng)效果

    一個(gè)uniapp小程序的項(xiàng)目,我們需要實(shí)現(xiàn)一個(gè)非常實(shí)用的功能——類似于錨點(diǎn)定位的交互效果,即在首頁(yè)中有多個(gè)tab(分類標(biāo)簽),每個(gè)tab對(duì)應(yīng)著不同的模塊,當(dāng)用戶點(diǎn)擊某個(gè)分類的tab時(shí),需要流暢地滾動(dòng)到對(duì)應(yīng)的內(nèi)容位置,提供更好的用戶體驗(yàn),
    2023-10-10
  • uniapp寬屏開發(fā)PC端方案及衍生問題解決辦法

    uniapp寬屏開發(fā)PC端方案及衍生問題解決辦法

    在uniapp中進(jìn)行寬屏開發(fā),主要是指在電腦端(PC端)使用寬屏顯示效果進(jìn)行應(yīng)用的開發(fā),這篇文章主要給大家介紹了關(guān)于uniapp寬屏開發(fā)PC端方案及衍生問題解決辦法,需要的朋友可以參考下
    2024-03-03
  • Vue使用electron轉(zhuǎn)換項(xiàng)目成桌面應(yīng)用方法介紹

    Vue使用electron轉(zhuǎn)換項(xiàng)目成桌面應(yīng)用方法介紹

    Electron也可以快速地將你的網(wǎng)站打包成一個(gè)原生應(yīng)用發(fā)布,下面這篇文章主要給大家介紹了關(guān)于Vue和React中快速使用Electron的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-11-11
  • Antd-vue Table組件添加Click事件,實(shí)現(xiàn)點(diǎn)擊某行數(shù)據(jù)教程

    Antd-vue Table組件添加Click事件,實(shí)現(xiàn)點(diǎn)擊某行數(shù)據(jù)教程

    這篇文章主要介紹了Antd-vue Table組件添加Click事件,實(shí)現(xiàn)點(diǎn)擊某行數(shù)據(jù)教程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • vue自定義指令實(shí)現(xiàn)元素滑動(dòng)移動(dòng)端適配及邊界處理

    vue自定義指令實(shí)現(xiàn)元素滑動(dòng)移動(dòng)端適配及邊界處理

    這篇文章主要為大家介紹了vue自定義指令實(shí)現(xiàn)元素滑動(dòng)移動(dòng)端適配及邊界處理詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09
  • Vuex之module使用方法及場(chǎng)景說明

    Vuex之module使用方法及場(chǎng)景說明

    這篇文章主要介紹了Vuex之module使用方法及場(chǎng)景說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • Vue 遞歸多級(jí)菜單的實(shí)例代碼

    Vue 遞歸多級(jí)菜單的實(shí)例代碼

    這篇文章主要介紹了Vue 遞歸多級(jí)菜單的實(shí)例代碼,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-05-05
  • Vue?事件處理函數(shù)的綁定示例詳解

    Vue?事件處理函數(shù)的綁定示例詳解

    這篇文章主要為大家介紹了Vue?事件處理函數(shù)的綁定示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-02-02

最新評(píng)論

丹凤县| 博爱县| 桐梓县| 淮阳县| 苏州市| 辉县市| 宣化县| 博湖县| 巩义市| 会泽县| 都昌县| 浠水县| 临漳县| 长岛县| 巨野县| 隆安县| 昌黎县| 北辰区| 宜兴市| 枞阳县| 石家庄市| 德令哈市| 沛县| 肥乡县| 洛隆县| 潞西市| 新津县| 玉门市| 台前县| 梁河县| 昌邑市| 米林县| 江阴市| 竹山县| 红桥区| 大渡口区| 吉安县| 麻栗坡县| 海林市| 台湾省| 商城县|