Struts2 and Jetty welcome-file-lists - struts2

I am trying to get a Struts2 webapp and Jetty to play well. For some reason with Struts interceptors and FilterDispatcher configured my welcome file never get picked up I always encounter a 404. I have index.jsp in my webapp but for some reason when accessing http://localhost/webapp I always encounter 404.
For now I have set default-action-ref to my index.jsp in struts.xml but this means even for really non-existent files the user would get redirected to the index page. Is there a cleaner way to ensure Jetty picks up the welcome file? The welcome file gets picked up if the struts FilterDispatcher is not used, so I reckon it has got something to do with the way struts is configured?
The web.xml is a fairly standard web.xml with nothing fancy(?!). As I said earlier, I suspect it has got something to do with the struts.xml configuration.
struts.xml:
<constant name="struts.serve.static" value="true"/>
<constant name="struts.codebehind.pathPrefix" value="/WEB-INF/pages/"/>
<constant name="struts.configuration.classpath.defaultParentPackage" value="cms-default"/>
<constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory"/>
<constant name="struts.custom.i18n.resources" value="cms-messages,cms-version"/>
<constant name="struts.multipart.maxSize" value="31457280"/>
<package name="cms-default" extends="codebehind-default">
<interceptors>
<interceptor-stack name="cmsStack">
<interceptor-ref name="alias" />
<interceptor-ref name="params" />
<interceptor-ref name="servletConfig" />
<interceptor-ref name="prepare" />
<interceptor-ref name="i18n" />
<interceptor-ref name="chain" />
<interceptor-ref name="modelDriven" />
<interceptor-ref name="fileUpload" />
<interceptor-ref name="checkbox" />
<interceptor-ref name="staticParams" />
<interceptor-ref name="conversionError" />
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="cmsStack" />
<default-action-ref name="index"></default-action-ref>
<global-results>
<result name="redirectToUrl" type="redirect">${redirectedToURL}</result>
</global-results>
<action name="index">
<result>/index.jsp</result>
</action>
</package>
FWIW, The problems I am encountering are almost the same ones mentioned in this email thread.
Updated With more information about the setup. Yeah the name webapp was just an example :)

Related

Struts 2 File upload works fine in Chrome and Firefox but not in IE

I am having issue with struts 2 file upload for excel file in Internet explorer. It works fine in Chrome and firefox, but I am not sure what I am missing for IE.
Here is the struts config I have:
<action name="uploadAction" method="submitServiceProfile" class="serviceProfileAction">
<!-- <interceptor-ref name="exception"/>
<interceptor-ref name="i18n"/> -->
<interceptor-ref name="fileUpload">
<param name="allowedTypes">application/ms-excel,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</param>
<!-- <param name="maximumSize">20480</param> -->
</interceptor-ref>
<interceptor-ref name="params">
<param name="excludeParams">dojo\..*,^struts\..*</param>
</interceptor-ref>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
<interceptor-ref name="store">
<param name="operationMode">STORE</param>
</interceptor-ref>
<interceptor-ref name="someStack"/>
<result name="success" type="redirectAction">managerPage</result>
<result name="error" type="redirectAction">managerPage</result>
<result name="input" type="tiles">homepage</result>
</action>
As suggested by user497087 (Thank you!), I completely removed allowedTypes, plus the interceptor-ref "fileupload". Now, the request gets to the action without a problem at any given browser.

Does anyone have any experience that interceptor(i18n) will cause no value during postback?

Assume I have this struts2 form
<s:form action="login" method="post">
<s:textfield key="login_name" name="login_name"/>
<s:submit></s:submit>
</s:form>
And also with this struts.xml setting
<constant name="struts.custom.i18n.resources" value="messageResource" />
<constant name="struts.devMode" value="true" />
<package name="login" namespace="/" extends="struts-default">
<action name="login" class="actions.index.index">
<interceptor-ref name="i18n"/>
<result name="LOGIN_SUCCESS">/Main.jsp</result>
<result name="LOGIN">/Login.jsp</result>
</action>
</package>
If I have added <interceptor-ref name="i18n"/> to the setting, login_name will have no value after form submitted; otherwise I can retrieve the value successfully.
If you want me to provide further detail, please just let me know. Thanks in advance!
You are adding only one interceptor for your action by doing so all other interceptors are not included. The default stack already includes i18n interceptor so no point to add it by yourself.

Global interceptor - runs before every action

How can I create an interceptor that will run before EVERY action in my application, without the need to specify it for every action separately?
From http://struts.apache.org/2.3.4.1/docs/how-do-we-configure-an-interceptor-to-be-used-with-every-action.html:
Create your own named stacks and declare a new default interceptor stack for a package
<package name="default" extends="struts-default" >
<interceptors>
<interceptor-stack name="myStack">
<interceptor-ref name="timer"/>
<interceptor-ref name="logger"/>
<interceptor-ref name="default-stack"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="myStack"/>
<action name="login" class="tutorial.Login">
<result name="input">login.jsp</result>
<result type="redirect-action">/secure/home</result>
</action>
</package>

Cannot exclude method in struts2 interceptor

I am having the opposite problem of the fellow in this question:
Struts 2: excluding method from validation from just the defaultStack interceptor
The above question involved all methods being excluded, my issue is that no methods are being excluded!
I'm trying to get my authenticationInterceptor to ignore the showLogin method of my LoginAction:
<interceptors>
<interceptor name="authorizationInterceptor" class="org.companyname.struts.interceptor.AuthorizationInterceptor"/>
<interceptor-stack name="appDefault">
<interceptor-ref name="authorizationInterceptor"/>
<interceptor-ref name="defaultStack">
<param name="exception.logEnabled">true</param>
<param name="exception.logLevel">ERROR</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="appDefault" />
<action name="loginInitial" class="org.companyname.struts.action.LoginAction" method="showLogin">
<interceptor-ref name="appDefault">
<param name="authorizationInterceptor.excludeMethods">showLogin</param>
</interceptor-ref>
<result name="success">/login.jsp</result>
</action>
However, each time I forward to loginInitial, the interceptor grabs it, even though my showLogin method is being excluded.
I've checked for naming issues, and have tried putting several different values in the interceptor-ref within the action, and nothing seems to work.
What's the proper way to skip the authorizationInterceptor when I forward to loginIntial?
I believe my issue is the type of interceptor I'm using, the AbstractInterceptor. So, I just use different interceptor stacks on the actions I don't want intercepted:
<interceptor-stack name="appDefaultWithAuth">
<interceptor-ref name="defaultStack">
<param name="exception.logEnabled">true</param>
<param name="exception.logLevel">ERROR</param>
</interceptor-ref>
<interceptor-ref name="authorizationInterceptor"/>
</interceptor-stack>
<interceptor-stack name="appDefaultNoAuth">
<interceptor-ref name="defaultStack">
<param name="exception.logEnabled">true</param>
<param name="exception.logLevel">ERROR</param>
</interceptor-ref>
</interceptor-stack>
<default-interceptor-ref name="appDefaultWithAuth" />
<action name="loginInitial" class="org.company.struts.action.LoginAction" method="showLogin">
<interceptor-ref name="appDefaultNoAuth"/>
<result name="success">/login.jsp</result>
</action>

Skipping default interceptor stack only on specific class

Hi
We have created a customized interceptor stack called appInterceptorStack and referred it as a <default-interceptor-ref name="appInterceptorStack"/>,
appInterceptorStack -> dont have validation and workflow interceptors attached to them.
But now for a specific action class I need to use validate method so I need validation interceptor
I created a new Interceptor stack with validation and workflow interceptors and referred it from action class. But only the default interceptor stack is getting executed. The changed one is not getting called, Please find the sample code below.
<package name="default" extends="struts-default">
<interceptor-stack name=”AppStack”>
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<interceptor-ref name="params"/>
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="params"/>
</interceptor-stack>
<interceptor-stack name=”GuiStack”>
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<interceptor-ref name="params"/>
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="params"/>
<interceptor-ref name="validation" />
<interceptor-ref name="workflow" />
</interceptor-stack>
<default-interceptor-ref name="AppStack"/>
<action name="test" class="com.jranch.Test">
<interceptor-ref name="GuiStack”/>
<result name="input">login.jsp</result>
<result name="success" type="redirect-action">/secure/home</result>
</action>
</package>
Can someone please help me?
The configuration looks correct. Can you turn on debug logging for com.opensymphony.
You can then see the interceptors being called in turn. This is the quickest way of seeing what is being called.

Resources