2015-01-14 45 views
0

我想調用javascript函數,但不是調用javascript函數,而是通過訪問SERVLET來重定向到另一個JSP頁面。 我發現了一個鏈接的幫助,他也使用了與我一樣的過程。來自JSP的javascript調用

鏈接,我發現:javascript function in jsp page

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Welcome</title> 

</head> 
<body> 
    <script type="text/javascript"> 
     function callCommom() { 
      alert("Method Called"); 
      return (false); 
     } 
    </script> 
    <form action="Common" method="post" onsubmit="return callCommon()"> 
     <table align="center" border="1"> 
      <tr> 
       <td align="center">Assignment</td> 
      </tr> 
      <tr> 
       <td> 
        <table align="center" border="1"> 
         <tr> 
          <td><label>Assignment Number</label></td> 
          <td><input type="text" name="assnName" id="assnname"> 
          </td> 
         </tr> 
         <tr> 
          <td align="center"><input type="submit" value="submit"></td> 
          <td align="center"><input type="button" name="btnClear" 
           id="clearButton" value="Clear"></td> 
         </tr> 
        </table> 
       </td> 
      </tr> 
     </table> 
    </form> 
</body> 
</html> 

請建議我......我需要你的幫助。

+0

你們是不是提交給servlet之前驗證在JavaScript形式或實際上,你並不要提交給servlet呢? – developerwjk

+0

您可以使用onclick上的提交按鈕調用相同的功能 – Prashant

回答

1

有一個排字錯誤錯誤。必須是:

<form action="Common" method="post" onsubmit="return callCommom()"> 
                  ^

或者:

function callCommon() { 
       ^
+0

OMG !!非常感謝你......我打破了我的頭,但我沒有注意到它。 :) – Brain

+1

不客氣。 - 別擔心。這些事情發生。很高興提供幫助。 :) –