這是我的場景。我有這個jsp的形式:如何顯示從servlet到jsp的變量值
的welcome.jsp
<div class="ajax-wrap" style="display: block; height:100%;">
<p class="overlay_title">
<%-- <span><%=request.getAttribute("mes_add_pageTitle")%></span> --%>
<% String userlabel=(String)request.getAttribute("mes_add_pageTitle");%>
</p>
</div>
,我有這是我的WelcomeServlet.java:
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String UsernameLabel="passing value";
request.setAttribute("mes_add_pageTitle",UsernameLabel); //Setting USernameLabel to mes_add_pageTitle
RequestDispatcher rd=request.getRequestDispatcher("/welcome.jsp");
rd.forward(request,response); //forwarded to welcome.jsp
}
我的問題是,爲什麼我得到的jsp空值。它應該顯示Username Label
,但它不工作..我的錯誤,請幫助。注意:Username Label
是一個標籤,所以我不需要獲取或發佈。謝謝
變量存儲在servlet和我想在jsp中顯示它們 – QWERTY
我的歡迎文件是index.jsp – QWERTY
我做到了。但我仍然得到空值。 。我的代碼有什麼問題? – QWERTY