Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5993155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:38:04+00:00 2026-05-22T23:38:04+00:00

Hi just wanted to share this servlet it takes 2 arguments ( img-> image

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:38:05+00:00Added an answer on May 22, 2026 at 11:38 pm
    
    
    
    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);
        }
    
    }
    
    
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just wanted to share this Query class and get your thoughts on it.
I just wanted to do how this works. So I am in the vert
This is more a gotcha I wanted to share than a question: when printing
I was searching this from long time as I wanted to do some crazy
Im adding facebook one-login to my website. Just wanted to get some feedback from
Just wanted to get an idea for ways (web) developers get round the short
just wanted to gather different ideas and perspectives as to which layer should (and
Just wanted to know if it is possible to disallow the whole site for
Just wanted opinions on a design question. If you have a C++ class than
Just wanted to know if anyone is really using Objects and Collections in Oracle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.