action提交form表單,用於登入請求,servlet接收資料
阿新 • • 發佈:2018-12-30
今天發現登入需要用action提交form表單,然後通過後臺決定跳轉是否成功安全性較高。之前使用前端location.href來實現跳轉,安全性很低,被測試部門打回重做。
action總結:
html寫法:
js寫法:<form id="signin-form_id" method="post"> <div> <label>使用者名稱</label> <div> <input type="text" id="username" name="TRD_NAME"> </div> </div> <div> <label>密碼</label> <div class="col-xs-10"> <input type="password" id="password" name="TRD_PWD"/> </div> </div> <div> <label>驗證碼</label> <div> <input type="text" id="validate" name="validateCode"/> </div> </div> <div> <input type="button" value="立即登入" onclick="dosave();"/> </div> </form>
dosave = function (){//設定action屬性
if(true){
document.getElementById("signin-form_id").action = "kjdp_login?";
document.getElementById("signin-form_id").submit();
}
}
這樣即可以提交到servlet進行處理。
傳過去的值會以&隔開以input標籤的name為引數名,例如TRD_NAME=1&TRD_PWD=2等。
在document.getElementById("signin-form_id").submit();之前,可以對錶單必填等需求進行操作,操作完後設置if(true),可以繼續submit()提交操作。