struts2 - execute action when .js file loads -



struts2 - execute action when .js file loads -

question: there way execute action on welcome.jsp file?

my problem: welcome.js file has string literals substituted java properties like:

<button value"${com.button.ok.literal}" ...

and substituted when action executed, problem initial doesn't execute action , there's no substition, struts.xml looks like:

<action name = "createprocess" class = "com.acme.actions.init" method="create"> <result name ="ok">/jsp/welcome.jsp</result> </action>

i tried execute empty action 'loadlabels', defining in welcom.js init():

funcion init(){ ... <% string checkfirst = (string)request.getattribute("checkfirst"); %> if ("<%=checkfirst %>" != "first"){ document.forms[0].action ="loadlabels.action?parameter=first"; document.forms[0].submit(); }

this works, i'm 100% sure there improve solution this.

you can embed javascript function in page , phone call whenever need execute action. javascript code little like

window.location = "${pagecontext.request.contextpath}/actionname";

call like

<input type="button" value="welcome!" onclick="welcomeactionfunction">

struts2

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -