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。