Skip to content

Instantly share code, notes, and snippets.

@rossabaker
Created June 30, 2011 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rossabaker/1055654 to your computer and use it in GitHub Desktop.
Save rossabaker/1055654 to your computer and use it in GitHub Desktop.
Scalatra Issue #57 -- works for me
package com.example
import org.scalatra._
class FormServlet extends ScalatraServlet with FlashMapSupport {
get("/form") {
<form action="/form-servlet/form" method="post">
<input type="submit" value="Submit" />
</form>
}
post("/form") {
flash("foo") = "bar"
redirect("/other-servlet/show-flash")
}
}
class OtherServlet extends ScalatraServlet with FlashMapSupport {
get("/show-flash") {
"Foo = " + flash("foo")
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>scalatra</servlet-name>
<servlet-class>
com.example.FormServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>scalatra</servlet-name>
<url-pattern>/form-servlet/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>other</servlet-name>
<servlet-class>
com.example.OtherServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>other</servlet-name>
<url-pattern>/other-servlet/*</url-pattern>
</servlet-mapping>
</web-app>
@chelm-spotuse
Copy link

When I execute this, it shows the flash message but if I reload the show-flash action the message stays. I extended the example a little bit:

package com.example

import org.scalatra._

class FormServlet extends ScalatraServlet with FlashMapSupport {
  get("/form") {
    <form action="/form-servlet/form" method="post">
      <input type="submit" value="Submit" />
    </form>     
  }     

  post("/form") {
    flash("foo") = "bar"
    redirect("/other-servlet/show-flash")
  }   

  get("/show-flash") {  
    "Foo = " + flash("foo")
  }
}

class OtherServlet extends ScalatraServlet with FlashMapSupport {
  get("/show-flash") {  
    "Foo = " + flash("foo")
  }

  get("/show-flash2") {  
    "Foo = " + flash("foo")
  }   
}

The following things happen:

  • When I submit the form the message is shown.
  • When I reload the message is still there
  • When I access /other-servlet/show-flash2 the message is still there
  • When I reload the message is still there
  • When I access /form-servlet/show-flash the message is still there
  • When I reload the message is gone (exception)

Another interesting detail:

If I access /other-servlet/show-flash as the first request, I get an exception (of course).
But if I submit the form afterwards it doesn't work anymore. I always get a NoSuchElementException, even if I repeat submitting the form.

I'm using jetty 6.1.26. Do you think jetty could be the problem?

@rossabaker
Copy link
Author

Commented on the issue. This is definitely a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment