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 8960983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:46:56+00:00 2026-06-15T15:46:56+00:00

I’m working with Eclipse and I just built a servlet that will take in

  • 0

I’m working with Eclipse and I just built a servlet that will take in a file name, and a file from a form and create a new file in my eclipse directory with the file name that the user provided. So if the user said firstImage for the file name and got an image from their desktop called stackoverflow.png then my servlet would create a firstImage.png file in my directory and put the contents of stackoverflow.png into it.

The problem is let’s say I fill out the form and write to the file gmustudent/images/firstImage.png. If I go to that url http://localhost:8086/gmustudent/images/firstImage.png nothing will be there. But once I go to the gmustudent project in eclipse, right click it and click Refresh then firstImage.png pops up in the directory and the url now works.

This is obviously a problem b/c I don’t want to have to refresh my project each time I use this form. So can anyone tell me how I can add some code to the end of my servlet that will refresh the project each time the servlet is run. Thank you.

  • 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-06-15T15:46:57+00:00Added an answer on June 15, 2026 at 3:46 pm

    Best way is to use a servlet and stream back images. Streaming is that we have a servlet that’s reading files in the server and it’s sending the bytes back in the response.

    public class ImageServlet extends HttpServlet {
    
        private static final long serialVersionUID = 1L;
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    
            response.setContentType("image/jpeg");
    
            String pathToWeb = getServletContext().getRealPath(File.separator);
            File f = new File(pathToWeb + "avajavalogo.jpg");
            BufferedImage bi = ImageIO.read(f);
            OutputStream out = response.getOutputStream();
            ImageIO.write(bi, "jpg", out);
            out.close();
    
        }
    
    }
    

    The web.xml.

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="tomcat-demo" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    
        <servlet>
            <servlet-name>ImageServlet</servlet-name>
            <servlet-class>test.ImageServlet</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>ImageServlet</servlet-name>
            <url-pattern>/image</url-pattern>
        </servlet-mapping>
    
    </web-app>
    

    The reason why your web url link doesn’t work is because you might have not mapped the directory in web.xml file. The best practice is to use a separate servlet like above to stream back images. Refer this question as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.