English 中文(简体)
圣杯中无法连载到圣杯中
原标题:GrailsParameterMap is not serializable in Grails
  • 时间:2012-05-28 09:47:05
  •  标签:
  • java
  • grails

当我在 http 会话中将地图保存如下时, 我有一个例外,

session.nextUrl = [controller: controllerName,
                               action: actionName,
                               params: params]

当我把上面的片段换成以下的片段时, 我也有同样的例外, 甚至是java. util.

java.util.Map nextUrl = new java.util.HashMap()

nextUrl.put("controller", controllerName)
nextUrl.put("action", actionName)
nextUrl.put("params", params)
session.setAttribute("nextUrl", nextUrl) 

我还可以看出,开会的收成/安排运作良好。

我怎样才能解决这个问题?

Thanks in advance, Prashant

最佳回答

问题在于,持有控制器参数的 params 映射类型 (GrailsParameterMap ) 控制器中的参数不执行 Sreabable 接口,这就是为什么你得到例外的原因。 解决方案我现在想到的是, 您需要专门为 params 创建一个新的 hashmap , 并复制所有参数, 并保存到会话中, 例如 :

// this is my pseudocode - haven t been doing groovy and java for long time
java.util.Map paramMap = new java.util.HashMap() // copy params here

foreach(p in params)
{
  paramMap.put(p.Key, p.Value)
}

java.util.Map nextUrl = new java.util.HashMap()

nextUrl.put("controller", controllerName)
nextUrl.put("action", actionName)
nextUrl.put("params", paraMap) // <- note paramMap, not params!

session.setAttribute("nextUrl", nextUrl)
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签