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
Add a ment  | 

3 Answers 3

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&param2=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