SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face javascript not working in jsp page

    hello fellow coders,
    im having problems running a javascript code and its giving me exceptions-->
    Code:
    HTTP Status 500 - 
    
    --------------------------------------------------------------------------------
    
    type Exception report
    
    message 
    
    description The server encountered an internal error () that prevented it from fulfilling this request.
    
    exception 
    
    org.apache.jasper.JasperException: Exception in JSP: /pages/admin/addbdgt.jsp:11
    
    8: <head>
    9: <title>Budget Master Administration</title>
    10: <meta name="GENERATOR" content="Microsoft FrontPage 3.0">
    11: <html:javascript src="bscript.js" staticJavascript="true"/>
    12: <!--  <SCRIPT LANGUAGE="JavaScript" SRC="bscript.js"></SCRIPT>  -->
    13: <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    14: </head>
    
    
    Stacktrace:
    	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:467)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    
    
    root cause 
    
    java.lang.NullPointerException
    	org.apache.struts.taglib.html.JavascriptValidatorTag.doStartTag(JavascriptValidatorTag.java:316)
    	org.apache.jsp.pages.admin.addbdgt_jsp._jspx_meth_html_005fjavascript_005f0(addbdgt_jsp.java:156)
    	org.apache.jsp.pages.admin.addbdgt_jsp._jspx_meth_html_005fhtml_005f0(addbdgt_jsp.java:120)
    	org.apache.jsp.pages.admin.addbdgt_jsp._jspService(addbdgt_jsp.java:91)
    	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    
    
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.23 logs.
    
    
    --------------------------------------------------------------------------------
    
    Apache Tomcat/5.5.23
    ive also done something like this
    Code:
    <html:form action="/BdgtMastAction" name="bdgtmastForm" type="publicity.BdgtMastForm" method="post"  onsubmit="return everything(this);">
    but when i use the <html:javascript> tag the validation fails and when i use the conventional <script> tag it works...(sort of).can someone throw some light on this problem?
    regards,
    ajos

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is more a JSP / Struts error which is not Javascript related. If you remove the onsubmit=".." does it load normally? if so, then try

    onsubmit="alert('test');"


  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gRoberts View Post
    this is more a JSP / Struts error which is not Javascript related. If you remove the onsubmit=".." does it load normally? if so, then try

    onsubmit="alert('test');"
    hi gRoberts,
    thanx for the reply.
    well the error/exception that im getting is pointing at -->
    HTML Code:
    <html:javascript src="bscript.js" staticJavascript="true"/>
    while if i write this-->
    HTML Code:
    <SCRIPT LANGUAGE="JavaScript" SRC="bscript.js"></SCRIPT>
    and then click on submit the validation takes place once i.e if the user doesnt enter the values and click enter then the javascript validation is fired...but if the user decides to click on submit without filling in the values again then the validation fails to fire...im confused right now i also did wat u said...onsubmit="alert('test');" but the same problem crept up again which i mentioned in bold...plz guide me regarding this...
    Last edited by ajos777; Oct 4, 2007 at 02:39. Reason: completed wat was left

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    onsubmit should always fire so it may be your javascript thats failing. Also, looking into this, I assume you are using Struts, which has validation for forms built in, or at least thats what i have seen.


  5. #5
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    would it be possible for you to open your page in your browser, and then copy and paste the source into here. Obviously remove any sensitive information and if possible, provide the javascript as well.

    if you are worried about posting on the live forum, by all means send via PM.


  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gRoberts View Post
    onsubmit should always fire so it may be your javascript thats failing. Also, looking into this, I assume you are using Struts, which has validation for forms built in, or at least thats what i have seen.
    as u said,the onsubmit is firing,i tested it with onsubmit="alert('test');" which on clicking submit is firing ...but only once and after clicking on ok a page shows up saying-->
    javax.servlet.ServletException: Incorrect integer value: '' for column 'Publicity_Code' at row 1.
    im just checking the validations for only a couple of text boxes,thats y im not using the validation framework...

  7. #7
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gRoberts View Post
    would it be possible for you to open your page in your browser, and then copy and paste the source into here. Obviously remove any sensitive information and if possible, provide the javascript as well.

    if you are worried about posting on the live forum, by all means send via PM.
    i surely can post that-->
    HTML Code:
    <%@ 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">
    <%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
    <html:html>
    <head>
    <title>Publicity Master Administration</title>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    [B]<html:javascript src="pscript.js"/>[/B]
    <!-- <SCRIPT LANGUAGE="JavaScript" SRC="pscript.js"></SCRIPT> -->
    </head>
    
    <body topmargin="0" leftmargin="0" bgproperties="fixed">
    <div align="left">
    <table border="0" width="100%">
      <tr>
        <td width="100%" bgcolor="#DFDFFF" background="images/niceblue.gif"><font face="Tahoma"
        color="#000000"><strong>P u b l i c i t y&nbsp;&nbsp; M a s t e r</strong></font></td>
      </tr>
    </table>
    <div align="left">
    <html:form action="/PubMasterAction" name="pubmasterForm" type="publicity.PubMasterForm" method="post" onsubmit="return everything(this);">
    <table border="0" cellpadding="0" cellspacing="0" width="100%" height="107">
      <tr>
        <td width="25%" height="41"><strong><small><font face="Tahoma"></font></small></strong></td>
        <td width="10%" height="41"></td>
        <td width="32%" height="41"><strong><small><font face="Tahoma"></font></small></strong></td>
        <td width="33%" height="41"></td>
      </tr>
      <tr>
        <td width="25%" height="25"><strong><small><font face="Tahoma">Publicity Code </font></small></strong></td>
        <td width="10%" height="25">
        <html:text property="publicity_code" name="pubmasterForm" size="5" maxlength="5"></html:text>
        </td>
        <td width="32%" height="25"><strong><small><font face="Tahoma">Publicity Code Description </font></small></strong></td>
        <td width="33%" height="25">
        <html:text property="publicity_head" name="pubmasterForm" size="25" maxlength="50"></html:text>
        </td>
      </tr>
      <tr>
        <td width="25%" height="21"><strong><small><font face="Tahoma">Expenditure Code</font></small></strong></td>
        <td width="10%" height="21">
        <html:text property="expenditure_code" name="pubmasterForm" size="5" maxlength="8"></html:text>
    	</td>
        <td width="32%" height="21"><strong><small><font face="Tahoma">Expenditure Code
        Description</font></small></strong></td>
        <td width="33%" height="21">
        <html:text property="expenditure_type" name="pubmasterForm" size="25" maxlength="50"></html:text>
        </td>
      </tr>
      <tr>
        <td width="25%" height="21"></td>
        <td width="10%" height="21"></td>
        <td width="32%" height="21"></td>
        <td width="33%" height="21"></td>
      </tr>
      <tr>
        <td width="25%" height="21"><strong><small><font face="Tahoma">Description</font></small></strong></td>
        <td width="42%" height="21" colspan="2">
        <html:text property="description" name="pubmasterForm" size="25" maxlength="255"></html:text>
    	</td>
        <td width="33%" height="21"></td>
      </tr>
      <tr>
        <td width="25%" height="20"><small><strong><font face="Tahoma"></font></strong></small></td>
        <td width="42%" height="20" colspan="2"></td>
        <td width="33%" height="20"></td>
      </tr>
      <tr>
        <td width="25%" height="21"><small><strong><font face="Tahoma">ED Approval Required</font></strong></small></td>
        <td width="42%" height="21" colspan="2">
        <html:select property="approval_flag" size="1">
        <html:option value="Y">Yes</html:option>
        <html:option value="N">No</html:option>
        </html:select>
        </td>
        <td width="33%" height="21"></td>
      </tr>
      <tr>
        <td width="25%" height="21"><strong><font face="Tahoma"><small></small></font></strong>
        <html:submit value="Submit" property="thesubmit">&nbsp;</html:submit>
        
        <!-- <input type="button" name="thesubmit" value="Submit" onclick="everything(form)"><strong><font face="Tahoma"> 
    	<small></small></font></strong> -->
        
        </td>
        <td width="42%" height="21" colspan="2"></td>
        <td width="33%" height="21"></td>
      </tr>
    </table>
    </html:form>
    </div>
    <hr>
    <strong><small><font color="#0080C0">
    <p align="center"></font><font color="#0080C0" face="Verdana">Response - Corporate
    1998-1999</font></small></strong>
    </div>
    </body>
    </html:html>
    my javascript file ->
    Code:
    function everything(form) {
    ispcode(form)
    isecode(form)
    ispdesc(form)
    isedesc(form)
    isdesc(form)
    allblanks(form) 
    }
    
    function allblanks(form) 
    {
     if(ispcode(form) && isecode(form) && ispdesc(form) && isedesc(form) &&   isdesc(form))
     {
       arch.submit() 
     }
     else if(ispcode(form) == false || isecode(form) == false || ispdesc(form) || isedesc(form) || isdesc(form)) 
     {
      compose(form)
     }
    }
    
    function compose(form) {
      var text = "You forgot to fill in correctly:" 
       
      if(ispcode(form) == false) {
       text += "\nPUBLICITY CODE"
      }
     
      if (isecode(form) == false) {
       text += "\nEXPENDITURE CODE"
      }
      if (ispdesc(form) == false) {
       text += "\nPUBLICITY HEAD DESCRIPTION"
      }
      if (isedesc(form) == false) {
       text += "\nEXPENDITURE TYPE"
      }
      if (isdesc(form) == false) {
       text += "\nDESCRIPTION"
      }
    
      alert(text)
    }
    
    
    function ispcode(form)
    {
     if (form.publicity_code.value == "") {
      return false
     }
     else {
      var len = form.publicity_code.value.length
      for (var k = 0; k < len; k++)
      {
        var c = form.publicity_code.value.substring(k, k+1);
         if(isNaN(parseInt(c))) 
         {
          return false
         }
      }
      return true
     }
    }
    
    function isecode(form)
    {
     if (form.expenditure_code.value == "") {
      return false
     }
     else {
      var len = form.expenditure_code.value.length
      if (len < 8) {return false}
      for (var k = 0; k < len; k++)
      {
        var c = form.expenditure_code.value.substring(k, k+1);
         if(isNaN(parseInt(c))) 
         {
          return false
         }
      }
      if(form.expenditure_code.value.substring(0,5) == form.publicity_code.value) 
      {
       return true
      }
      else {return false}
     }
    }
    
    function ispdesc(form)
    {
     if (form.publicity_head.value == "") {
      return false
     }
     else {
      return true
     }
    }
    function isedesc(form)
    {
     if (form.expenditure_type.value == "") {
      return false
     }
     else {
      return true
     }
    }
    function isdesc(form)
    {
     if (form.description.value == "") {
      return false
     }
     else {
      return true
     }
    }

  8. #8
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry, could you open it in your browser and post the results of the JSP page as I can't parse the JSP Tags or assume their output.


  9. #9
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gRoberts View Post
    sorry, could you open it in your browser and post the results of the JSP page as I can't parse the JSP Tags or assume their output.
    do you mean the plain html from the view source?if its that,im unable to view the html source right clicking the browser...is there any other way?

    ok i found my view source-->
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    
    
    
    <html>
    <head>
    <title>Publicity Master Administration</title>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <SCRIPT LANGUAGE="JavaScript" SRC="pscript.js"></SCRIPT> 
    </head>
    
    <body topmargin="0" leftmargin="0" bgproperties="fixed">
    <div align="left">
    <table border="0" width="100%">
      <tr>
        <td width="100%" bgcolor="#DFDFFF" background="images/niceblue.gif"><font face="Tahoma"
        color="#000000"><strong>P u b l i c i t y&nbsp;&nbsp; M a s t e r</strong></font></td>
      </tr>
    </table>
    <div align="left">
    <form name="pubmasterForm" method="post" action="/struts-test/PubMasterAction.do" onsubmit="return everything(this);">
    <table border="0" cellpadding="0" cellspacing="0" width="100%" height="107">
      <tr>
        <td width="25%" height="41"><strong><small><font face="Tahoma"></font></small></strong></td>
        <td width="10%" height="41"></td>
        <td width="32%" height="41"><strong><small><font face="Tahoma"></font></small></strong></td>
        <td width="33%" height="41"></td>
      </tr>
      <tr>
        <td width="25%" height="25"><strong><small><font face="Tahoma">Publicity Code </font></small></strong></td>
        <td width="10%" height="25">
        <input type="text" name="publicity_code" maxlength="5" size="5" value="">
        </td>
        <td width="32%" height="25"><strong><small><font face="Tahoma">Publicity Code Description </font></small></strong></td>
        <td width="33%" height="25">
        <input type="text" name="publicity_head" maxlength="50" size="25" value="">
        </td>
      </tr>
      <tr>
        <td width="25%" height="21"><strong><small><font face="Tahoma">Expenditure Code</font></small></strong></td>
        <td width="10%" height="21">
        <input type="text" name="expenditure_code" maxlength="8" size="5" value="">
    	</td>
        <td width="32%" height="21"><strong><small><font face="Tahoma">Expenditure Code
        Description</font></small></strong></td>
        <td width="33%" height="21">
        <input type="text" name="expenditure_type" maxlength="50" size="25" value="">
        </td>
      </tr>
      <tr>
        <td width="25%" height="21"></td>
        <td width="10%" height="21"></td>
        <td width="32%" height="21"></td>
        <td width="33%" height="21"></td>
      </tr>
      <tr>
        <td width="25%" height="21"><strong><small><font face="Tahoma">Description</font></small></strong></td>
        <td width="42%" height="21" colspan="2">
        <input type="text" name="description" maxlength="255" size="25" value="">
    	</td>
        <td width="33%" height="21"></td>
      </tr>
      <tr>
        <td width="25%" height="20"><small><strong><font face="Tahoma"></font></strong></small></td>
        <td width="42%" height="20" colspan="2"></td>
        <td width="33%" height="20"></td>
      </tr>
      <tr>
        <td width="25%" height="21"><small><strong><font face="Tahoma">ED Approval Required</font></strong></small></td>
        <td width="42%" height="21" colspan="2">
        <select name="approval_flag" size="1"><option value="Y">Yes</option>
        <option value="N">No</option></select>
        </td>
        <td width="33%" height="21"></td>
      </tr>
      <tr>
        <td width="25%" height="21"><strong><font face="Tahoma"><small></small></font></strong>
        <input type="submit" name="thesubmit" value="Submit">
        
        <!-- <input type="button" name="thesubmit" value="Submit" onclick="everything(form)"><strong><font face="Tahoma"> 
    	<small></small></font></strong> -->
        
        </td>
        <td width="42%" height="21" colspan="2"></td>
        <td width="33%" height="21"></td>
      </tr>
    </table>
    </form>
    </div>
    <hr>
    <strong><small><font color="#0080C0">
    <p align="center"></font><font color="#0080C0" face="Verdana">Response - Corporate
    1998-1999</font></small></strong>
    </div>
    </body>
    </html>

  10. #10
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You problem is everything is not returning a boolean value to stop the form from posting. I've made changes to your javascript and it seems to work fine now:

    Code:
    function everything(form) {
        var errors = 0;
        if(!ispcode(form))
            errors++;
        if(!isecode(form))
            errors++;
        if(!ispdesc(form))
            errors++;
        if(!isedesc(form))
            errors++;
        if(!isdesc(form))
            errors++;
        if(errors == 0)
            return true;
        else {
            compose(form);
            return false;
        }
    }
    
    function compose(form) {
      var text = "You forgot to fill in correctly:" 
       
      if(ispcode(form) == false) {
       text += "\nPUBLICITY CODE"
      }
     
      if (isecode(form) == false) {
       text += "\nEXPENDITURE CODE"
      }
      if (ispdesc(form) == false) {
       text += "\nPUBLICITY HEAD DESCRIPTION"
      }
      if (isedesc(form) == false) {
       text += "\nEXPENDITURE TYPE"
      }
      if (isdesc(form) == false) {
       text += "\nDESCRIPTION"
      }
    
      alert(text)
    }
    
    
    function ispcode(form)
    {
     if (form.publicity_code.value == "") {
      return false
     }
     else {
      var len = form.publicity_code.value.length
      for (var k = 0; k < len; k++)
      {
        var c = form.publicity_code.value.substring(k, k+1);
         if(isNaN(parseInt(c))) 
         {
          return false
         }
      }
      return true
     }
    }
    
    function isecode(form)
    {
     if (form.expenditure_code.value == "") {
      return false
     }
     else {
      var len = form.expenditure_code.value.length
      if (len < 8) {return false}
      for (var k = 0; k < len; k++)
      {
        var c = form.expenditure_code.value.substring(k, k+1);
         if(isNaN(parseInt(c))) 
         {
          return false
         }
      }
      if(form.expenditure_code.value.substring(0,5) == form.publicity_code.value) 
      {
       return true
      }
      else {return false}
     }
    }
    
    function ispdesc(form)
    {
     if (form.publicity_head.value == "") {
      return false
     }
     else {
      return true
     }
    }
    function isedesc(form)
    {
     if (form.expenditure_type.value == "") {
      return false
     }
     else {
      return true
     }
    }
    function isdesc(form)
    {
     if (form.description.value == "") {
      return false
     }
     else {
      return true
     }
    }


  11. #11
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gRoberts View Post
    You problem is everything is not returning a boolean value to stop the form from posting. I've made changes to your javascript and it seems to work fine now:
    first and foremost i want to thank u for all the help and support that u have provided me, i really appreciate the time u have taken for me,as for the code that uve given me, its working the way it shud be to be honest with u ive been on this for the last 6 days and had already lost hope in this,ive no clue abt javascript this was my first time.the only problem that im facing is using the <html:javascript> tag coz its working well in the conventional <script> tag..thanx for this very much

  12. #12
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad to be of assistance. as for the <html:javascript> tag I have no idea unfortunately. I assume you just need to pass it an path to the js file.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •