-1
我嘗試在Servlet中將文本保存爲屬性並將其轉發到HTML頁面。然後需要在Html頁面主體中顯示它。 幫我發送數據作爲對HTML的響應,然後幫助顯示HTML頁面中的值。 在JSP中工作正常。但我需要將響應發送到html頁面並顯示它。如何從Servlet中獲取參數到Html頁面?
Here i am using Request dispatcher for send the request and response to html page.
but i am not clear with how to display it in html.Help me tp solve.
thanks
//NewServlet.java
public class NewServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
request.setAttribute("Cricket", "Sachin");
RequestDispatcher rd = request.getRequestDispatcher("index.html");
rd.forward(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
}
//index.html
'index.html'不是jsp –
當你有jsp的時候使用JSTL –
我能想到的唯一方法就是預處理html,並用你想顯示的任何東西替換「TODO寫內容」。 –