Want to pass the java value into javascript functi

2019-07-03 13:41发布

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

标签: java jsp struts
3条回答
放荡不羁爱自由
2楼-- · 2019-07-03 14:19

it's work for me :

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

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

查看更多
老娘就宠你
3楼-- · 2019-07-03 14:20

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

<html:submit property = "save" styleClass = "button_c" onclick = "return SubmitPage('update', '<%=timeVal %>')">Save</html:submit>
查看更多
Animai°情兽
4楼-- · 2019-07-03 14:25

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.

查看更多
登录 后发表回答