jsp - Action method not being called while calling from window.open() in javascript -
i trying open new window , call action in process in struts 2.
the problem jsp opens action not being called till press refresh or go new jsp.
i want action execute , redirect corresponding jsp right redirects jsp corresponding first mapped result.
action call javascript:
function displaygraph(graphname) { alert("displaygraph"); var url = 'drawcmgraph?data=' + encodeuricomponent(graphname); alert(url); window.open(url, "_blank", "directories=no, status=no,width=550, height=200,top=0,left=0"); }
action mapping in struts.xml
<action name="drawcmgraph" class="com.casealerts.action.homeaction" method="drawgraph"> <result name="success">/casealerts/test.jsp</result> <result name="error">/casealerts/error.jsp</result> </action>
web.xml
<?xml version="1.0" encoding="utf-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="webapp_id" version="3.0"> <display-name>comp</display-name> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <!--this listener handles caching of data when server context loaded.--> <listener-class>complistener</listener-class> </listener> <welcome-file-list> <welcome-file>/casealerts/login.jsp</welcome-file> </welcome-file-list> </web-app>
action
package com.casealerts.action; import java.util.arraylist; import java.util.list; import java.util.vector; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpsession; import org.apache.log4j.logger; import org.apache.struts2.interceptor.servletrequestaware; import com.opensymphony.xwork2.actionsupport; import com.opensymphony.xwork2.modeldriven; import com.opensymphony.xwork2.preparable; import com.casealerts.businessdelegate.homepagecmdelegate; import com.casealerts.formbean.homeform; public class homeaction extends actionsupport implements modeldriven<homeform>,preparable,servletrequestaware { /** * */ private static final long serialversionuid = 272240572969090988l; logger log=new log4jhelper().getlogger(getclass()); homedelegate hpd=null; private httpservletrequest request; homeform form=null; private httpsession session=null; @override public void setservletrequest(httpservletrequest request) { // todo auto-generated method stub this.request=request; } @override public void prepare() throws exception { // todo auto-generated method stub form=new homeform(); } @override public homeform getmodel() { // todo auto-generated method stub return form; } public string drawgraph() { session=request.getsession(true); hpd=new homedelegate(form,session); string result=hpd.getgraphdata("alert", 1); return result; } }
var url = 'drawcmgraph?data=' + encodeuricomponent(graphname); alert(url);
try changing
var url = 'drawcmgraph.action?data=' + encodeuricomponent(graphname); alert(url);
Comments
Post a Comment