0

The following is not working

<%session.setAttribute("key", ${key});%>


<c:redirect url="/example/request/first.jsp"> 
    <c:param name="send" value="done"/>
    <c:param name="key"><%= session.getAttribute("key") %></c:param>
</c:redirect>   

result: "send=done&key=%24%7bkey%7d"

How would I pass my session attribute in so that the correct value would come across?

*update - What is happening is that I am saving a uploaded file to a directory on the server. I don't know how to accomplish that using a ajax call so I am using the form post method.

My ajax call which saves the record to the database is executing before my form post so the key(for that record) is lost once I get forwarded to the jsp page taking care of the file upload.

I am trying to redirect to my main page from there preserving the key so that I can load the record for the user. I was hoping that maybe session data could accomplish that for me by keeping the key from the ajax call to the form post. Messy I know... My solution needs to work on at least Internet explorer 8.

Trevor
  • 16,080
  • 9
  • 52
  • 83

1 Answers1

4

Why are you mixing taglibs/EL with oldschool scriptlets?

Just use Expression Language (EL, those ${} things) exclusively.

<c:param name="key" value="${key}" />

I strongly recommend to configure your webapp to completely disable scriptlets (those <% .. %> things) by the appropriate entry in web.xml, so that this kind of mistakes can be avoided in the future.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Do you know how to set a session attribute using tag libraries or expression language? – Trevor Jul 17 '13 at 20:27
  • 2
    ``. But setting session attributes has nothing to do in a JSP. It should be done by the controller. – JB Nizet Jul 17 '13 at 20:38
  • 1
    Please click the "Expression Language" link in my answer. The `${key}` already resolves to a page/request/session/application attribute. I'm not seeing any point of re-setting it as session attribute using a scriptlet here. – BalusC Jul 17 '13 at 20:47