【发布时间】:2016-11-29 06:23:08
【问题描述】:
我尝试将文本保存为 servlet 中的属性并将其转发到 HTML 页面。然后需要在 Html 页面正文中显示它。 帮助我将数据作为对 HTML 的响应发送。然后帮助在 HTML 页面中显示值。 在 JSP 中工作正常。但我需要将响应发送到 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 写入内容”替换为您想要显示的任何内容。
-
但是使用 JSP 会容易得多
-
你为什么需要 html?
标签: java html jsp servlets requestdispatcher