-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写内容”。 –