String to ArrayList<String>
I am implementing Spring MVC. Different String values are displayed on the jsp page.
Help me move those String values to ArrayList to reduce that bulky code.
 @Controller("Control")
 Public Class Controller{
 ...
 @RequestMapping()
public String init(RenderRequest request, RenderResponse response,
        Model model) {
    try {
        String auth = request.getAuthType();  //All these Strings to be moved to ArrayList<String>
        String context = request.getContextPath();
        String ETags = request.getETag();
        String remoteuser = request.getRemoteUser();
        String sessionID = request.getRequestedSessionId();
        String resContent = request.getResponseContentType();
        String scheme = request.getScheme();
        String getServerName = request.getServerName();
        String getWindowID = request.getWindowID();
        PortletMode getPortletMode = request.getPortletMode();  //If these different types could also be moved <?开发者_运维知识库>
        PortalContext Pcontext = request.getPortalContext();
        model.addAttribute("Name", "Sallu");
        model.addAttribute("auth",auth);
        model.addAttribute("context", context);
        model.addAttribute("ETags",ETags);
        model.addAttribute("remoteuser", remoteuser);
        model.addAttribute("sessionID",sessionID);
        model.addAttribute("resContent",resContent);
        model.addAttribute("scheme", scheme);
        model.addAttribute("getServerName",getServerName);
        model.addAttribute("getWindowID", getWindowID);
        model.addAttribute("getPortletMode",getPortletMode);
        model.addAttribute("Pcontext",Pcontext);
    } catch (Exception ex) {
        LOG.error(ErrorUtil.convertStackTraceToString(ex));
    }
    return JSP_Page;
}
Also Help me change the JSP too using
   <%My JSP%>
   <tr>
    <td>Pcontexts------${Pcontext}</td>
</tr>
<tr>
    <td>auths------${auth}</td>
</tr>
    ...
    //To be changed to something using <c:ForEach or some Loop>
Update:
When I add this to the controller, and do as Bozho showed in the JSP, it still does not work:
model.addAttribute("paramsMap", request.getParameterMap()); 
You can use request.getParameterMap() - it will give you a Map that you can then iterate in the JSP:.
<c:forEach items="${paramValues}" var="mapEntry">
    <td>${mapEntry.key}</td>
    <td>${mapEntry.value}</td>
</c:forEach>
paramValues above is an implicit variable that contains the map.
When using forward, this you need nothing else to do in the controller. You can use:   model.addAttribute("paramsMap", request.getParameterMap()), but it should not be necessary.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论