Port number changing in URL while redirecting to different JSP pages - struts2

We have an application URL
xxx.xxx.com and post Authentication, user request goes to load balancer URL and there are 2 websphere instances behind the load balancer URL.
load balancer URL is: host.xxx.com:21758 and the individual instances are
instance1.xxx.com:61158, instance2.xxx.com:21758
Issue what we are facing is post login and when the request goes into instance1, URL in the address bar is changing to host.xxx.com:61158 i.e. load balancer URL & Instace1 port number.
In the code we are not using any HTTP parameters like Host or any port number specifically
Environment is
Websphere 8.5.5.9 server, Struts 2.3.X and JSPs
<action name="home">
<result>/jsp/login.jsp</result>
</action>
<action name="login" class="com.XXX.YYYY.admin.web.struts.action.LoginAction">
<result name="success">/jsp/adminhome.jsp</result>
<result name="error">/jsp/error.jsp</result>
<result name="home" type="chain">home</result>
</action>
When request comes in, LoginAction gets invoked and post some validation, "Success" string is returned. Based on that string another JSP needs to be shown up. But instead of that, URL in the address bar is getting changed.
URL should not be changed

Related

Struts action result redirecting to wrong URL

Our application is hosted under a folder in a domain. When struts action result returns a JSP page, it is removing the that folder. So the JSP page is not loading
Our App is hosted in domain.com/vendor
Here vendor is a folder under the domain
When action result return a JSP page, URL is
domain.com/project1/private/attendance.jsp
Here "vendor" folder is missing
<package name="private" namespace="/private" extends="struts-default">
<action name="attendanceRegister" class="com.emob.web.PunchAction"
method="listAttendance">
<result name="success">/private/attendance.jsp</result>
</action>
</package>
Please let me know the configuration so that the folder is returned in result URL

struts 2 redirection (type="redirect-Action" , type="redirect") in xml redirecting to http instead of https

We used SSL on strut-2 project. At multiple places, we used redirection in struts.xml like below in code .
<action name="bo_act_creditNote_Save"
class="com.skilrock.lms.web.accMgmt.common.CreditNoteAtBoAction"
method="doCreditNoteBo">
<result name="success" type="redirect-action">
<param name="actionName">bo_act_creditNote_redirect</param>
</result>
</action>
<action name="bo_act_creditNote_redirect">
<result>
/com/skilrock/lms/web/accMgmt/backOffice/bo_act_creditNote_Success.jsp
</result>
</action>
due to ssl browser show some error that
http://mydomain/com/skil/lms/web/userMgmt/bo_act_creditNote_redirect.action'. This request has been blocked; the content must be served over HTTPS.
And the result page is not coming as transaction completed successfully.
To resolve this issue, we removed redirection and replace with JSP page wherever it is used.
But we want to keep redirection action.

Struts2 - Get the url from error page

I'm currently trying to make a CMS project, where I will be making a so called "blogsite", something like wordpress. The problem that I'm facing is that I want to access the blogsite directly via url.
Something like
local/CMS/site_name
normally it would be a 404 error since there is nothing that will be mapped there, so i catched it in the web.xml by
<error-page>
<error-code>404</error-code>
<location>/checkBlogUrl.action</location>
</error-page>
so I can process the URL request there, query the site, if it exists forward the page to there, if not error.jsp.
The code I'm currently trying to make it work is
HttpServletRequest request = ServletActionContext.getRequest();
String a = request.getServerName() +" : " + request.getRequestURI()
+ " : "+ request.getServletPath() +" : "+ request.getLocalName();
System.out.println(a);
which sadly returned this
mycms : /CMS/checkBlogUrl.action : /checkBlogUrl.action : mycms
How can I get the site_name?
Or, is there a better way to "forward" the url for a database query?
Instead of using the error page in the web.xml, I changed it to named parameters.
<action name="/*" class="checkBlogUrl">
<param name="blogSiteUrl">{1}</param>
<result type="redirectAction">
<param name="actionName">checkBlogUrl</param>
<param name="blogSiteUrl">{1}</param>
</result>
</action>
As noted by Andrea Ligios, web.xml error page will drop the original request URI so the question was not feasible
EDIT:
putting ${requestScope['javax.servlet.error.request_uri']} in the JSP page will give you the URI, then maybe you can pass it to the action someway or another

struts 2 and sitemesh localization

i am using struts 2 and sitemesh. I can change locale in my login page without problem just by setting a request parameter named with 'request_locale' parameter. But in all other pages i am using sitemesh for decorating header and footer. And i tried to set same parameter for other pages but no luck. These are some of the other codes that i tried in my Login Action:
request.getSession(false).setAttribute("WW_TRANS_I18N_LOCALE", newLocale);
ActionContext.getContext().setLocale(newLocale);
session.put(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE, newLocale);
When i write out these settings i see everything is ok.
But when i write out
<c:out value="${pageContext.request.locale.language}"/>
it is always showing browsers Accept-Language and it doesnt make any localization.
How can i make localization to work with sitemesh?
I tried to redirect from login action to an action named home with request locale parameter and then this action redirects to index.jsp. Everything is ok now.
And i set default action as home action so when user enters root page from address bar it is activing home action so i18n interceptor and intercoptors are becaming active.
This is login.action in struts.xml:
<action name="login" class="wateron.login.LoginAction" >
<result type="redirectAction">
<param name="actionName">home?request_locale=${request_locale}</param>
<param name="namespace">/</param>
</result>
</action>
And this is home action in struts.xml :
<package name="default" extends="struts-default" namespace="">
<default-action-ref name="home" />
<action name="home">
<result>/index.jsp</result>
</action>
</package>
Thanks for reference question :
How to use interceptor on the default page?

Struts2 token interceptor always fails

Im trying to make it so that once i submit this form i cannot hit the back button, but with the current configuration I cannot even get the page/form to load. I can't seem to figure out why "invalid.token" is always being triggered thus redirecting me to index.jsp no matter what I have the token tag in my form like im supposed to. If i use the "excludeMethods" filter and exclude View then my page loads but I can hit the back button freely so it still does not work properly. I have tried moving the interceptor-ref above and below my noLoginStack but it dosen't make a difference. Based on my debugging my actual java class isn't even being hit, so its failing before then. What am I doing wrong?
My action declaration:
<action name="viewAppointmentLetter" class="edu.ucr.c3.rsummer.controller.instructor.ManageAppointmentLetters">
<interceptor-ref name="noLoginStack"/>
<interceptor-ref name="token" />
<result name="invalid.token">/index.jsp</result>
<result name="error" type="redirectAction">index.do</result>
<result name="input">/instructor/assigned_appts.jsp</result>
<result name="view">/instructor/assigned_appts.jsp</result>
<result type="redirectAction">index.do</result>
</action>
My assigned_appts.jsp:
<s:form action="saveAppointmentLetter" onsubmit="return verifySubmit();">
<s:token name="token" />
.....
</s:form>
If its any clue I always get this in my console
WARN org.apache.struts2.util.TokenHelper - Could not find token name in params.
In struts2 the order of interceptor is very important. you should follow this order.
<interceptor-ref name="token"/>
<interceptor-ref name="noLoginStack"/>
USe TokenSession interceptor.Had to handle result by result name="invalid.token" in struts.xml in specific action.
The page from which your action is generated at that page you have to write <s:token> tag in the header

Resources