MyException - 我的异常网
当前位置:我的异常网» Java Web开发 » servlet 急解决思路

servlet 急解决思路

www.MyException.Cn  网友分享于:2013-01-13  浏览:9次
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。

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有