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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:57:54+00:00 2026-06-08T07:57:54+00:00

I have a pretty standard Spring 3.0.7 web app The structure is like this

  • 0

I have a pretty standard Spring 3.0.7 web app

The structure is like this

WebContent/
    resources/
      myStaticConent/
    WEB-INF/
       views/
       myProtectedContent/

I am using the <mvc:resources> configuration for the static content and my controllers get views using the InternalViewResolver from WEB-INF/views

Now I have a requirement to return non-JSP content ( JPGs,PNGs,HTML,etc ) from a protected directory in WEB-INF

So a user might enter a URL like http:myWebApp/myProtectedContent and hit my protected content controller.

@Controller
public class HelloWorldController {

@RequestMapping(value="/myProtectedContent")
public String index() {
  return "myjpg.jpg";
 }
}

Essentially I want to conditionally serve a file just like I would a view. Anyone know how this can be done ?

I looked at some of the other methods here, Streaming using Inputstream seems overkill for files that are essentially static. Can I register another “view” type ? I need this to appear l( from the web browser side ) like a standard http request response ( like the current view implementation).

I would really like to avoid inventing my own file handling methods unless there is some reason why using the file access methods are better then Springs “other” view resolvers like ResourceBundleResolver

So the requirement is
Conditionally respond to a http request with variable file type (jpg,png,html) from inside WEB-INF without wrapping in a jsp or having the file interpreted by the JSTL view. The names of the files are known and static. The controller will determine the file name based on its own business logic.

  • 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-08T07:57:57+00:00Added an answer on June 8, 2026 at 7:57 am

    You can reproduce the behavior of the underlying implementation of <mvc:resources/> which is org.springframework.web.servlet.resource.ResourceHttpRequestHandler, which essentially streams out the content of the static files – You can like ResourceHttpRequestHandler, extend from org.springframework.web.servlet.support.WebContentGenerator which has extensive support for sending last-modified and caching related headers, and finally to stream the content also there is a utility that Spring provides:

    org.springframework.util.FileCopyUtils.copy(resource.getInputStream(), response.getOutputStream());
    

    Updated:

    @Controller
    public class HelloWorldController implements ApplicationContextAware  {
        ApplicatonContext ctx = ...;
    
        @RequestMapping(value="/myProtectedContent")
        public void index(HttpServletRequest req, HttpServletResponse res) {
            Resource resource = ctx.getResource("classpath:staticpath/myjpg.jpg");
            FileCopyUtils.copy(resource.getInputStream(), response.getOutputStream());
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is just some pretty standard code I have tried. What I am trying
I have a pretty standard project with Spring Security. I have a login form
I have what I would assume is a pretty standard setup...spring, jpa (hibernate) and
I have pretty standard Qmail toaster installation. I'm using the dot files to set
I have a pretty standard database sitting on SQL Server. To manage the data
I have a pretty standard Repository pattern going, where repositories are injected into my
I have a pretty standard .NET MVC 3 application that uses Ninject for dependency
My problem: require_once '/includes/aws-sdk-1.5.2/sdk.class.php'; My environment: I have a pretty standard PHP site that
I have some js (show/hide pretty standard I guess): <script> function showTransactions(transactions){ $('.steps').hide() $('#'
I have pretty simple jquery code : $(document).ready(function(){ $('img.marqFl').on({ mouseenter: function() { $(this).animate({height: 300},

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.