• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Do I need to "add" encodeURL for "action" tag in this case ?

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my struts-config.xml, I set

<action path="/action" input="/input.jsp"
scope="request">
<forward name="success" path="/success.jsp" />

So, the scopeis set as "request" here, but in my Action class I use "session" and store objects in the session. So, in my input.jsp I will do

input.jsp:
************************
<html:form action="<%= response.encodeURL("/action") %>" >
....
</html:form>
*************************

Now my questions are --

Do I need to do anything for the struts-config.xml's "path=/action" ?
Do I need to do anything for the struts-config.xml's "forward path="/success.jsp" ?

Or will struts automatically take care of it ? Please be aware I use "scope=request" for each <action> definition, so do I need to do anything explicitly in the struts-config.xml or any other places besides what I mentiioned for the <html:form action=..> ?
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Struts performs encodeURL automatically. You don't need to include it in the action attribute of html:form, or anywhere else. As long as you use struts tags and forwards, the encodeURL is being done for you.
 
Artemesia Lakener
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Merrill Higginson:
Struts performs encodeURL automatically. You don't need to include it in the action attribute of html:form, or anywhere else. As long as you use struts tags and forwards, the encodeURL is being done for you.



Thanks. But I am just curious -- There must a reason why struts chooses to use "encodeURL" and usually that's when it realizes the "session" is being used (otherwise, no need). Is my guess correct ? If so, then how does struts know "session" is used ? In my case, I do NOT set scope=session, instead I set scope=request. So, how can struts know I am using session ? Is it because it finds I use session in Action class ?

I am just trying to understand better about the mechanism. Thanks.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The way that encodeURL is handled is dependent on your application server. It is only used if the App server is configured to use URL rewriting to keep track of sessions. Otherwise, it is ignored. The most common way to keep track of session is with cookies. The application server puts a cookie on the user's browser and retrieves it every time a request is made. It uses that cookie to associate the user with a session.

The trouble with cookies, however, is that they can be turned off by individual users, making it impossible to track the sesion. So, if you want to be sure to track sessions even for users who don't accept cookies, configure your app server to use url Rewriting. With url rewriting, every time you call encodeURL, the app server will append a session ID as a parameter to any link. It will then look for that session id when the user communicates with the server.

I hope this answers your question.
 
Artemesia Lakener
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Merrill Higginson:
The way that encodeURL is handled is dependent on your application server. It is only used if the App server is configured to use URL rewriting to keep track of sessions. Otherwise, it is ignored. The most common way to keep track of session is with cookies. The application server puts a cookie on the user's browser and retrieves it every time a request is made. It uses that cookie to associate the user with a session.

The trouble with cookies, however, is that they can be turned off by individual users, making it impossible to track the sesion. So, if you want to be sure to track sessions even for users who don't accept cookies, configure your app server to use url Rewriting. With url rewriting, every time you call encodeURL, the app server will append a session ID as a parameter to any link. It will then look for that session id when the user communicates with the server.

I hope this answers your question.



Thanks Merill, but I was not concerned about "how encodeURL" works. I was curious about "Under what condition will the struts use encodeURL 'automatically' ?"

You said, "encodeURL is performed by struts automatically".

1. If we do NOT use session anywhere in our Action code, and in struts-config.xml every "scope" is set as "request". Then will "encodeURL" be applied automatically as well ? I doubt.

2. If I set "scope=request", but in Action class I use session myself (of course, server 'creates' for me). will encodeURL be applied by struts automatically ?

3. if I set "scope=session" in struts-config.xml, then I am sure encodeURL will be applied because struts-config.xml is the file it reads.

My point is there must be a way to "tell" struts that you are using "session" so that it can apply "encodeURL" for you. Right ?

By the way, I added a encodeURL to the <html:form action=".."> and it still works, so it doesn't hurt though it may be unnecessary.
 
Artemesia Lakener
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now my guess is struts *always* uses "encodeURL" no matter you use "session" or not. Is that right ? A
reply
    Bookmark Topic Watch Topic
  • New Topic