admin管理员组文章数量:1287598
I am new to stackoverflow i have doubt regarding calling jsp from javascript file. my file contain one html file with javascript(home.html) and one jsp file(login.jsp) In html(home.html) file i have 2 textbox and 2 buttons one for login and another for reset.when i click the login button i should call a js for textbox field validation (ie for if any one of the textbox is empty it shows "text fields should not be empty" alert msg to user)if both the textbox have value then it should call a jsp page(login.jsp).Thanks in advance
I am new to stackoverflow i have doubt regarding calling jsp from javascript file. my file contain one html file with javascript(home.html) and one jsp file(login.jsp) In html(home.html) file i have 2 textbox and 2 buttons one for login and another for reset.when i click the login button i should call a js for textbox field validation (ie for if any one of the textbox is empty it shows "text fields should not be empty" alert msg to user)if both the textbox have value then it should call a jsp page(login.jsp).Thanks in advance
Share Improve this question asked Sep 18, 2010 at 10:21 MohanMohan 3,9039 gold badges34 silver badges42 bronze badges 1- can you give us some code of what you have done so far? – AutomatedTester Commented Sep 18, 2010 at 10:25
3 Answers
Reset to default 2<script language="JavaScript">
function val(){
var name=...
var pass=...
if(name==" "||pass==" ")
{
alert("fields should not be empty");
}
else{
var jspcall = "login.jsp?param1=value1¶m2=value2";
window.location.href = jspcall;
}
}
</script>
<form id="myform" action="login.jsp" method="post">
<input name="u" id="u"> Username<br>
<input name="p" id="p" type="password"> Password
</form>
<script>
document.getElementById('myform').addEventListener('submit', function(e) {
if (!document.getElementById('u').value || !document.getElementById('p').value)
e.preventDefault();
}, false);
</script>
Try using jquery
$.post("login.jsp", { name: "John", time: "2pm" },
function(data){
alert("Data Loaded: " + data);
});
ref: http://api.jquery./jQuery.post/
本文标签: from javascript call a jsp pageStack Overflow
版权声明:本文标题:from javascript call a jsp page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741308440a2371510.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论