Wrox Home  
Search P2P Archive for: Go

  Return to Index  

servlets thread: calling one servlet file into another


Message #1 by bikashpaul_2001@y... on Mon, 18 Jun 2001 09:20:52
Dear sir,
How I call my first servlet into my second servlet.Following r my 
codes.Iam using res.sendRedirect("url");.But it not properly working.My 
1st servlet converting xml to html file and my 2nd servlet converting html 
file to .rb file.My problem is that without writting html file in c 
directory servlet going to convert html file and giving error(Creating 
test8.rb: ERROR: unable to open file: file:///mnt_c/checkw.html )Please 
guide me where I done a mistake.Following r my codes:-

It is 1st servlet:-
-------------------

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class chain1 extends HttpServlet
	{
	  public void doGet(HttpServletRequest req,HttpServletResponse res)
		throws ServletException,IOException
	        {
			
			 res.setContentType("text/html");
			 PrintWriter out=res.getWriter();
			 
			  Runtime r = Runtime.getRuntime();
			  Process p=null;		  
			  try
				{
				  p=r.exec("c:\\saxon.bat");
   				  	 	  
				}
			  catch(Exception e)
				{
				  out.println("Error from execution" + 
e.toString());
				}
				
			res.sendRedirect("http://127.0.0.1:7001/Start");
		   }
		 
		}

It is 2nd servlet:-
------------------
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class chain2 extends HttpServlet
	{
	  public void doGet(HttpServletRequest req,HttpServletResponse res)
		throws ServletException,IOException
	        {
			
			 res.setContentType("text/html");
			 PrintWriter out=res.getWriter();
			
			BufferedReader b = new BufferedReader( new 
InputStreamReader(req.getInputStream()));
               	  	String line1 = b.readLine();
               		while((line1=b.readLine()) !=null)
				{
				   FileWriter f1=new FileWriter
("c:\\checkw.html");
				   f1.write(line1);
				   f1.close();
				}
		
			  Runtime r = Runtime.getRuntime();
			  Process p=null;		  
			  try
				{
				  p=r.exec("e:\\soft 
dumps\\rbmake\\rbmake -o test8 c:\\checkw.html");
   				  BufferedReader in = new BufferedReader
(new InputStreamReader(p.getInputStream()));
				  String line=null;
				  while((line=in.readLine()) !=null)
					{
					  out.println(line);
					}	 	  
				}
			  catch(Exception e)
				{
				  out.println("Error from execution" + 
e.toString());
				}
			     
			
		   }
		 
		}
With Regards
Bikash

  Return to Index