Want to pass the java value into javascript function in jsp

ぃ、小莉子 提交于 2019-12-12 13:26:58

问题


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

回答1:


it's work for me :

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

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




回答2:


Rather using that i will advise you to use value like this in your JavaScript function

var tt = <%=(String)request.getAttribute("myDate")%>
alert(tt+ "Done this....");

Hope this will help you.




回答3:


Use '<%=timeVal %>' instead of <%=timeVal %> in Javascript method:

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


来源:https://stackoverflow.com/questions/15682881/want-to-pass-the-java-value-into-javascript-function-in-jsp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!