使用document.forms[0].submit()时的注意事项

本文探讨了POST+GET混用可能导致的中文乱码问题,并建议尽量避免这种做法。若必须混用,文章提供了通过encodeURIComponent()及URLDecoder.decode()解决乱码的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下面这种方式是一种post+get请求混用的情况,可能导致中文乱码问题(乱码问题可能是跟tomcat的配置有关)。为了避免中文乱码问题,强烈建议不要使用下面这种方式:

document.forms[0].method="post";
document.forms[0].action="/testManage_editTest?pageNow="+pageNow;
document.forms[0].submit();

如果在“.action”属性中需要传参数,则用get方法;如果没有参数,用post方法。如果非得post+get混用,但是又存在中文乱码时,需要在每个有乱码的地方,对输入框进行encodeURIComponent()+java代码中URLDecoder.decode()来解决,这样做很麻烦。

<!DOCTYPE html> <html> <head> <title>登录/注册</title> <link rel="stylesheet" href="styles.css"> <script> function showLoginForm() { document.getElementById('loginForm').style.display = "block"; document.getElementById('registerForm').style.display = "none"; } function showRegisterForm() { document.getElementById('loginForm').style.display = "none"; document.getElementById('registerForm').style.display = "block"; } function validateLoginForm() { var username = document.forms["loginForm"]["username"].value; var password = document.forms["loginForm"]["password"].value; if (username == "") { alert("请输入用户名"); return false; } if (password == "") { alert("请输入密码"); return false; } } function validateRegisterForm() { var username = document.forms["registerForm"]["username"].value; var email = document.forms["registerForm"]["email"].value; var password = document.forms["registerForm"]["password"].value; if (username == "") { alert("请输入用户名"); return false; } if (email == "") { alert("请输入邮箱"); return false; } if (password == "") { alert("请输入密码"); return false; } } </script> </head> <center> <body> <div class="container"> <h2>登录/注册</h2> <div class="tabs"> <button class="tab" onclick="showLoginForm()">登录</button> <button class="tab" onclick="showRegisterForm()">注册</button> </div> <!-- 登录表单 --> <form id="loginForm" name="loginForm" style="display: none;" onsubmit="return validateLoginForm()"> <div class="form-group"> <label for="loginUsername">用户名:</label> <input type="text" id="loginUsername" name="username" required> </div> <div class="form-group"> <label for="loginPassword">密码:</label> <input type="password" id="loginPassword" name="password" required> </div> <div class="form-group"> <button type="submit">登录</button> </div> </form> <!-- 注册表单 --> <form id="registerForm" name="registerForm" style="display: none;" onsubmit="return validateRegisterForm()"> <div class="form-group"> <label for="registerUsername">用户名:</label> <input type="text" id="registerUsername" name="username" required> </div> <div class="form-group"> <label for="registerEmail">邮箱:</label> <input type="email" id="registerEmail" name="email" required> </div> <div class="form-group"> <label for="registerPassword">密码:</label> <input type="password" id="registerPassword" name="password" required> </div> <div class="form-group"> <button type="submit">注册</button> </div> </form> </div> </center> </body> </html> 怎么把跳转插进去
05-29
将修改的代码给我完整的写出来,这是原本整体的VAB代码 Private Sub CommandButton1_Click() Dim objIEApp As InternetExplorerMedium Dim objIEDoc As Object Dim objIETable As Object Dim objClip As DataObject Dim objSheet As Worksheet Dim src, ac, name, pas, web, lang src = "Bugzilla" ac = "account" name = "A3" pas = "B3" web = "B1" Set objSheet = Sheets(src) Set objBuglist = Sheets(ac) 'check system language Dim LocaleID As Long '创建IE的实例 'Set objIEApp = New InternetExplorerMedium Set objIEApp = CreateObject("InternetExplorer.Application") '测试显示IE浏览器,测试完成后,可以注释掉 objIEApp.Visible = True '跳转到登陆界面 objIEApp.navigate "https://logincas.tp-link.com:8443/login?service=http://bugzilla.tp-link.com/" '等待IE浏览器启动成功 Do While objIEApp.Busy: DoEvents: Loop '等待登陆界面完成 Do Until objIEApp.readyState = READYSTATE_COMPLETE: DoEvents: Loop '获取登陆界面 Set objIEDoc = objIEApp.document '填充登陆界面的用户名和密码--可以通过F12查看网页的源代码 'With objIEDoc.forms(0) ' .UserName.Value = objBuglist.Range(name).Value ' .Password.Value = objBuglist.Range(pas).Value ' .loginBtn.Click '.submit 'End With '等待浏览器响应 'Do While objIEApp.Busy: DoEvents: Loop '等待登陆成功 'Do Until objIEApp.readyState = READYSTATE_COMPLETE: DoEvents: Loop '登陆成功,跳转至表格存在的界面 objIEApp.navigate objBuglist.Range(web).Value Do While objIEApp.Busy: DoEvents: Loop Do Until objIEApp.readyState = READYSTATE_COMPLETE: DoEvents: Loop '获取页面中的表格元素mytable是表的Id Set objIEDoc = objIEApp.document Set objIETable = objIEDoc.all.Item("buglist_table") '将表格html从网页复制到excel sheet中 If Not objIETable Is Nothing Then Set objClip = New DataObject objClip.SetText "" & objIETable.outerHTML & "" objClip.PutInClipboard objSheet.Select objSheet.Range("A1").Select 'objSheet.PasteSpecial lang LocaleID = Application.LanguageSettings.LanguageID(msoLanguageIDUI) Select Case LocaleID Case 2052 objSheet.PasteSpecial "Unicode 文本", xlPasteAll Case 1028 objSheet.PasteSpecial "Unicode 文本", xlPasteAll Case 1033 objSheet.PasteSpecial "Unicode Text", xlPasteAll Case Else objSheet.PasteSpecial "Unicode Text", xlPasteAll End Select End If 'close 'er up objIEApp.Quit Set objIEApp = Nothing If Sheets("schedule").Cells(2, 1) = "" Then Sheets("Bugzilla").Range("A2:A" & Sheets("Bugzilla").[B65536].End(xlUp).Row).copy Sheets("schedule").Range("A2") add_http (2) End If Sheets("schedule").Activate End Sub
最新发布
08-12
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值