0
我正在使用一個restful方法,我想將一個列表傳遞給一個jsp文件。
這裏是RESTful方法:
如何將一個列表轉發給一個jsp文件?
@Path("myRest")
public void handleRequestInternal() throws Exception {
try {
Request req = new Request();
List<String> roles = manager2.getAllRoles();
req.setAttribute("roles", roles);
java.net.URI location = new java.net.URI("../index.jsp");
throw new WebApplicationException(Response.temporaryRedirect(location).build());
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
我用webApplicationException爲了去我想要的頁面。 (其實我發現沒有其他的方式來轉發或重定向,用寧靜的方法時)
這裏是我的JSP文件:
<% if(request.getAttribute("roles") != null){%>
<% Object obj = (Object)request.getAttribute("roles");
List<String> roles = (List<String>) obj;%>
<select name="role">
<%int size = roles.size();%>
<%for(int i = 0; i < size; i++){ %>
<option value = "<%= roles.get(i)%>"><%= roles.get(i)%>
<%} %>
</select>
<%}%>
但我從request.getAttribute什麼( 「角色」)
問題是什麼?
啊,你的意思是把我的變量到url中。好吧,因爲這不是安全的事情,那對我來說工作得很好。謝謝。 –