redirect - How to set a default page for wrong action requests in struts2? -
i have followed apache tutorial following code runs error.
error>>>>
caused by: org.xml.sax.saxparseexception; systemid: file:/c:/users/target/project-1.0/web- inf/classes/struts.xml; linenumber: 53; columnnumber: 15; content of element type "package" must match "(result-types?,interceptors?,default-interceptor-ref?,default-action-ref?,default- class-ref?,global-results?,global-exception-mappings?,action*)".
please note actions , packages correctly defined once copy redirect code runs error. code
<package name="default" namespace="/" extends="struts-default"> <default-action-ref name="underconstruction"></default-action-ref> <action name="underconstruction"> <result>notfound.jsp</result> </action> <result-types> <result-type name="tiles" class="org.apache.struts2.views.tiles.tilesresult"/> </result-types> <action ....> </action> ,,, </package>
when change follwing line
<result>notfound.jsp</result>
to
<result type="tiles">notfound.jsp</result>
the application ran when enter wrong address not show notfound.jsp page, throw not found action exception.
when try following code application runs not redirect wrong requests underconstruction page
<package name="default" namespace="/" extends="struts-default"> <result-types> <result-type name="tiles" class="org.apache.struts2.views.tiles.tilesresult"/> </result-types> <action ....> </action> ,,, </package> <package name="hello" extends="struts-default"> <default-action-ref name="underconstruction"></default-action-ref> <action name="underconstruction"> <result>notfound.jsp</result> </action> </package>
the above configuration have shown tiles-integration. can not copy-paste , make working rocket. there various ways achieve goals, of approch follows:
1st approch
create global result-declaration error or exception
<global-results> <result name="error">/error.jsp</result> <result name="specific_exception">/unique.jsp</result> <result name="login" type="redirectaction">login.jsp</result> </global-results>
and validate , return respective string ex error or success action based invaidation.
2nd approch
you can redirect in action mapping
<action name="your_action_name"> <result type="success">success.jsp</result> <result type="error">notfound.jsp</result> </action>
Comments
Post a Comment