Dav*_*ave 5 jboss spring jsp model input
我正在使用Spring 3.2.11.RELEASE和JBoss 7.1.3.Final和Java 6.我在控制器中使用了这个方法
@RequestMapping(value = "/method", method = RequestMethod.GET)
public String myMethod(final Model model,
final HttpServletRequest request,
final HttpServletResponse response,
final Principal principal)
...
model.addAttribute("paramName", "paramValue");
Run Code Online (Sandbox Code Playgroud)
请注意我如何在模型中添加属性.我的问题是,在这个页面所服务的JSP页面上,我如何迭代模型中的所有属性并将它们输出为HIDDEN输入字段,其中INPUT的名称是属性名称,值是我插入的使用该属性的模型?
编辑:响应给出的答案,这是JSP解决方案的输出.请注意,那里没有模型属性.
<input type='hidden' name='javax.servlet.jsp.jspRequest' value='org.springframework.web.context.support.ContextExposingHttpServletRequest@7a0a4c3f'>
<input type='hidden' name='javax.servlet.jsp.jspPageContext' value='org.apache.jasper.runtime.PageContextImpl@3939794a'>
<input type='hidden' name='appVersion' value='???application.version???'>
<input type='hidden' name='javax.servlet.jsp.jspResponse' value='org.owasp.csrfguard.http.InterceptRedirectResponse@722033be'>
<input type='hidden' name='javax.servlet.jsp.jspApplication' value='io.undertow.servlet.spec.ServletContextImpl@14c1252c'>
<input type='hidden' name='org.apache.taglibs.standard.jsp.ImplicitObjects' value='javax.servlet.jsp.el.ImplicitObjectELResolver$ImplicitObjects@23c27a49'>
<input type='hidden' name='javax.servlet.jsp.jspOut' value='org.apache.jasper.runtime.JspWriterImpl@b01a1ba'>
<input type='hidden' name='javax.servlet.jsp.jspPage' value='org.apache.jsp.WEB_002dINF.views.lti.launch_jsp@1dcc48bf'>
<input type='hidden' name='javax.servlet.jsp.jspConfig' value='io.undertow.servlet.spec.ServletConfigImpl@3fd40806'>
Run Code Online (Sandbox Code Playgroud)
模型属性是“请求范围”对象,您可以执行以下操作(我使用 JSTL):
<c:forEach items="${requestScope}" var="par">
<c:if test="${par.key.indexOf('attrName_') > -1}">
<li>${par.key} - ${par.value}</li>
</c:if>
</c:forEach>
Run Code Online (Sandbox Code Playgroud)
由于没有过滤器,您将拥有所有请求范围对象,因此我按我们想要检查的模型属性进行过滤
我使用这段代码进行了测试:
@RequestMapping(method = { RequestMethod.GET }, value = { "/*" })
public String renderPage(Model model) throws Exception
{
String requestedUrl = req.getRequestURI();
int indice = requestedUrl.lastIndexOf('/');
String pagina = requestedUrl.substring(indice + 1);
try
{
String usernameUtente = "default username utente";
if (StringUtils.hasText(getPrincipal()))
{
usernameUtente = getPrincipal();
}
model.addAttribute("usernameUtente", usernameUtente);
model.addAttribute("webDebug", webDebug);
for(int i = 0; i<10; i++)
{
model.addAttribute("attrName_"+i, "attrValue_"+i);
}
return pagina;
}
catch (Exception e)
{
String message = "Errore nell'erogazione della pagina " + pagina;
logger.error(message, e);
return "genericError";
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我所看到的输出(我省略了不相关的打印,但请注意,您将打印所有请求范围对象:
attrName_0 - attrValue_0
attrName_1 - attrValue_1
attrName_2 - attrValue_2
attrName_3 - attrValue_3
attrName_4 - attrValue_4
attrName_5 - attrValue_5
attrName_6 - attrValue_6
attrName_7 - attrValue_7
attrName_8 - attrValue_8
attrName_9 - attrValue_9
Run Code Online (Sandbox Code Playgroud)
我希望这可以帮助
安吉洛
| 归档时间: |
|
| 查看次数: |
2902 次 |
| 最近记录: |