<%@taglib uri="/struts-tags" prefix="s"%>
</s:form>
<br>
<b>Interceptor test</b>
<s:form action="simple">
<s:textfield name="message" label="message"/>
<s:submit value="submit"/>
</s:form>
Action file:
package action;
public class Simple {
String message,Status="action is not invoked";
public String execute() throws Exception
{
Status="action is invoked";
return "Success";
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getStatus() {
return Status;
}
}
Myinterceptor:
package interceptors;
import java.util.Enumeration;
import javax.servlet.ServletRequest;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import com.opensymphony.xwork2.util.ValueStack;
public class myinterceptor implements Interceptor {
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void init() {
// TODO Auto-generated method stub
}
@Override
public String intercept(ActionInvocation ae) throws Exception {
//preprocessing logic
ServletRequest req=ServletActionContext.getRequest();
ValueStack v=ae.getStack();
Enumeration<String> e=req.getParameterNames();
while(e.hasMoreElements())
{
String pname=e.nextElement();
String pvalue=req.getParameter(pname);
v.setValue(pname, pvalue);
}
// get the next compponent invoked
String str=ae.invoke();
return "Myjsp";
}
}
result.jsp
:
<%@taglib uri="/struts-tags" prefix="s"%>
<b>Result is:<s:property value="result"/></b>
<br/>
<jsp:include page="index.jsp"></jsp:include>
MyJsp.jsp
:
<b>notworking</b>
struts.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="action">
<result-types>
<result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
</result-types>
<interceptors>
<interceptor name="params" class="com.opensymphony.xwork2.interceptor.ParametersInterceptor"/>
<interceptor name="ps" class="interceptors.myinterceptor"></interceptor>
</interceptors>
<default-interceptor-ref name="params"></default-interceptor-ref>
<action name="adder" class="action.AdderAction">
<result name="success" >/result.jsp</result>
</action>
<action name="simple" class="action.Simple">
<interceptor-ref name="ps"/>
<result name="Success">/status.jsp</result>
<result name="Myjsp">/MyJsp.jsp </result>
</action>
</package>
</struts>
My question is that I am returning a different string from the interceptor than that of the action file, still the view of action is being generated using action string to map result, and not of the interceptor why?