当前位置: 代码迷 >> Java Web开发 >> servlet 急解决思路
  详细解决方案

servlet 急解决思路

热度:99   发布时间:2016-04-17 17:10:09.0
servlet 急!!!
servlet..
public   void   doGet(HttpServletRequest   request,   HttpServletResponse   response)
throws   ServletException,   IOException   {
response.setContentType(CONTENT_TYPE);
String   id= "1 ";

request.setAttribute(id, "id ");
PrintWriter   out   =   response.getWriter();
out.println( " <html> ");
out.println( " <head> <title> NewsServlet </title> </head> ");
out.println( " <body   bgcolor=\ "#ffffff\ "> ");
out.println( " <input   type= 'hidden '   name= 'id '   value= ' "+id+ " '> ");
out.println( " <script> window.navigate( 'maupdatehealthNews.jsp ') </script> ");
out.println( " </body> ");
out.println( " </html> ");
out.close();
}
maupdatehealthNews.jsp

<html>
<body>
<%
  String   id=(String)request.getAttribute( "id ");
  out.print(id);
%>
</body>
</html>

为什么得不到servlet的id   值啊


------解决方案--------------------
servlet..
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
String id= "1 ";

request.setAttribute(id, "id ");


RequestDispatcher view=request.getRequestDispatch( " 'maupdatehealthNews.jsp ");
view.forward(request,response);//把请求响应对象带入到jsp中

这样就行了,不要用servlet写html。
  相关解决方案