Hi just wanted to share this servlet it takes 2 arguments ( img-> image name , rot ->rotation of the images) loads the image from the images directory rotates it and outputs it to the servlet stream
you can find it in the answer below
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
package at.buchinger.mapdisplay; import java.awt.geom.AffineTransform; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.Iterator; import javax.imageio.ImageIO; import javax.imageio.ImageWriter; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Servlet implementation class RotatedImage */ public class RotatedImage extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public RotatedImage() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String img = (String) request.getParameter("img"); String path = getServletContext().getRealPath("image/"+img); String r; r=request.getParameter("rot"); if(r==null){ r="0"; } double rot = Double.parseDouble( r); BufferedImage image = ImageIO.read(new File(path)); AffineTransform tx = new AffineTransform(); tx.rotate(Math.toRadians(rot), image.getWidth()/2, image.getHeight()/2); AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR); image = op.filter(image, null); ServletContext sc = getServletContext(); String filename = getServletContext().getRealPath(path); // Get the MIME type of the image String mimeType = sc.getMimeType(filename); if (mimeType == null) { sc.log("Could not get MIME type of "+filename); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } // Set content type response.setContentType(mimeType); ServletOutputStream out = response.getOutputStream(); Iterator iter = ImageIO.getImageWritersByMIMEType(mimeType); ImageIO.write(image, "png", out); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }