0% found this document useful (0 votes)
39 views1 page

El Mismo Resultado Puede Obtenerse Con La Versión Siguiente Del Servlet Que Es Más Simple

This document contains code for a servlet that reads a file and writes its contents to an output stream. It catches any exceptions. It overrides the doGet and doPost methods to call the processRequest method. The document notes that the same result can be achieved with a simpler servlet that redirects to an image file location.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views1 page

El Mismo Resultado Puede Obtenerse Con La Versión Siguiente Del Servlet Que Es Más Simple

This document contains code for a servlet that reads a file and writes its contents to an output stream. It catches any exceptions. It overrides the doGet and doPost methods to call the processRequest method. The document notes that the same result can be achieved with a simpler servlet that redirects to an image file location.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

out = response.

getOutputStream();
byte [] datas = new byte [ (int) raf.length() ];
while ( (raf.read( datas )) > 0 )
{
out.write( datas );
}
out.flush();
}
catch(Exception e)
{
e.printStackTrace();
}
}

@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
processRequest(request, response);
}

@Override
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
processRequest(request, response);
}
}

El mismo resultado puede obtenerse con la versin siguiente del servlet que es ms
simple.

package es.eni.ri;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ResponseHttp2 extends HttpServlet


{
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
response.sendRedirect("images/titi.jpg");
}

@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
processRequest(request, response);
}

www.fullengineeringbook.net

You might also like