我有一個FrontController,它在自制的REST框架中返回Representation。我有一些XmlRepresentation,JsonRepresentation,我現在想要一個JspRepresentation。一個UserJspRepresentation可以用來表示用戶的頁面或片段。那麼一個JSP將是可以使用如何解析JSP頁面並以String結果得到結果?
我可以做一些前瞻性/包括的東西模板,但我想的東西更加孤立,並得到結果作爲對象。 forward()方法返回void。
喜歡的東西:
HttpServletRequest request = getHttpServletRequest();
User user = getUser();
request.setAttribute("user", user); // The Jsp will be aware of the user
JspRepresentation representation = new JspRepresentation(request, "userPage.jsp");
String result = representation.toString();// this is hard to get the displayed page !!!
的問題是:如何獲得JSP頁面作爲一個String對象?
現在我只能考慮使用Java客戶端,這是不是輕量級的......我也看了碧玉API中,但什麼也沒有發現明顯的。
據我所知,JSP規範不允許在給定的JSP引擎內部,必須有一種方法來創建文檔。 很顯然,我將不得不放棄我JspRepresentation,因爲我不想擰緊,以一種特定的技術。 –
維基百科:「JSP已被棄用遺留回落」 –
當你使用JSF框架,是的。而不是當你使用純JSP沒有JSF或與如Struts,Spring MVC的,等更多細節另一個框架:http://stackoverflow.com/questions/4845032/wheres-the-official-jsp-tutorial/4847062 #4847062 – BalusC