Want to pass the java value into javascript function in jsp

24,349

it's work for me :

<html:submit property = "save" styleClass = "button_c" onclick = "return SubmitPage('<%=timeVal %>')">Save</html:submit>

('<%=timeVal %>') // between single Quotation

Share:
24,349
NoNaMe
Author by

NoNaMe

Updated on September 15, 2020

Comments

  • NoNaMe
    NoNaMe over 3 years

    I am trying to pass a string value to a JavaScript function by taking from request parameter in JSP, in my struts based project. here is the code:

    <%
    String timeVal = "Not found";   
        if(request.getAttribute("myDate")!=null){       
            timeVal= (String)request.getAttribute("myDate");
        } 
    %>
    

    and then pass it in function as parameter

    <html:submit property = "save" styleClass = "button_c" onclick = "return SubmitPage('update', <%=timeVal %>)">Save</html:submit>
    

    Where the JavaScript function is

    function SubmitPage(action, aa)
    {   
    
    alert("Date is  ...." + aa);
    
    }
    

    But when i try to run this it gives me an error

    HTTP Status 400 - Request[/AMResourceLibraryListAction] does not contain handler parameter named ref
    

    With message on web page.

    Request[/AMResourceLibraryListAction] does not contain handler parameter named ref
    

    Thanks in advance.

    EDIT Here is stack trace

    [ERROR] DispatchAction - -Request[/AMResourceLibraryListAction] does not contain handler parameter named ref
    
  • NoNaMe
    NoNaMe about 11 years
    This way avoid the exception but take <%=timeVal %> as string not variable
  • NoNaMe
    NoNaMe about 11 years
    This way avoid the exception but take <%=timeVal %> as string not variable
  • mehdi
    mehdi about 11 years
    in this question timeVal is a String, If it is not, can Convert?
  • NoNaMe
    NoNaMe about 11 years
    timeVal is a variable of type String having variable value... that i am getting from a servlet....