日期:2014-05-18  浏览次数:20605 次

关于servlet跳转到jsp并传递参数的问题
我的servlet代码:
public   class   isValidate   extends   HttpServlet   {
public   void   init()   {

}

public   void   doGet(HttpServletRequest   req,   HttpServletResponse   res)
throws   ServletException,   IOException   {
res.setContentType( "text/plain;   charset=utf-8 ");
PrintWriter   out   =   res.getWriter();
String   filepath   ;
String   filename;
filename   =   req.getParameter( "radio ");
if(filename==null)
out.println( " <script> alert( '请选择要验证的文件 ') </script> ");
filepath   =   getServletContext().getRealPath( "/ ")+ "sig\\data\\idl\\ "+filename;

/*
  *   下面调用idlj对idl文件进行检测
  */
String   temp   =   getServletContext().getRealPath( "/ ")
+   "sig\\data\\temp\\ ";   //   idlj生成文件的临时存放路径;
try   {
String   command   =   "idlj   -td   "   +   temp   +   "   "   +   filepath;
Process   process   =   Runtime.getRuntime().exec(command);
BufferedReader   reader   =   new   BufferedReader(new   InputStreamReader(
process.getErrorStream()));
String   line   =   null;
String   mess   =   " ";
boolean   err   =   true;
while   ((line   =   reader.readLine())   !=   null)
{mess+=line+ "\r "; err=false;}
process.waitFor();
reader.close();
process.destroy();
// File   tempFile   =   new   File(temp);
// tempFile.delete();
if(err)
out.println( " <script> alert( '恭喜,文件通过语法验证! ');top.main.location.href= 'syntaxAnalysis.jsp '; </script> ");
else   {
req.setAttribute( "message ",   mess);
getServletConfig().getServletContext().getRequestDispatcher( "/display.jsp ").forward(req,   res);   //servlet跳转
}


}   catch   (Exception   e)   {
e.printStackTrace();
}
out.close();

}//   doGet

public   void   doPost(HttpServletRequest   req,   HttpServletResponse   res)
throws   ServletException,   IOException   {
doGet(req,res);
}
}
==========================
其中跳转语句为:
req.setAttribute( "message ",   mess);
getServletConfig().getServletContext().getRequestDispatcher( "/display.jsp ").forward(req,   res);   //servlet跳转
//直接getServletContext().getRequestDispatcher( "/display.jsp ").forward(req,   res);   也不行
==========================
PS:每次保存完之后,res.setContentType( "text/plain;   charset=utf-8 ");这一行总是被eclipse编译成灰底色。是不是和这个有关系?
PS2:这个servlet和目标jsp页面display.jsp都是在top.main这个frame中的!同一个frame中,应该没有关系吧?!   另:我在地址栏直接输入servlet的地址(保开frame框架了),还是不能跳转!



------解决方案--------------------
lg