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

  • Home
  • SEARCH
  • 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 8033157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:36:31+00:00 2026-06-05T01:36:31+00:00

I want to be able to return a specific jsp page from restful service

  • 0

I want to be able to return a specific jsp page from restful service given the page name as a PathParam. These pages will be added and removed by a different group of people after the application is deployed.

I believe using the Viewable object is a decent way to go (I’m open to a better/correct way.)

@GET
@Produces(MediaType.TEXT_HTML)
@Path("{page}") 
public Response showJSP(@PathParam("page") String page) {
    Viewable loadPage = null;

    try {
      loadPage = new Viewable("/" + page, null);
    } catch (Exception e) {
        return Response.status(404).build();
    }

  Response ret = Response.ok(loadPage).build();

//    if (ret.getStatus() == 500){
//          ret = Response.status(404).build();
//      }

 return ret;
}

The above is my experimental code and contains my attempts to handle the error.

This works fine as long as the page name is a valid jsp page. If I pass in an invalid page I get

500 Internal Server Error

java.io.IOException: The template name, /someWrongFileName, could not be resolved to a fully qualified template name.....

What I’ve figured out is this error is generated internal to the Viewable object so it’s not throwing an exception and the Response of course is a valid page so checking for the 500 status doesn’t work.

I can hack in several things that I’m pretty sure are wrong such as, I really do not want to toString the generated page and regex for the error text.

I would like to be able to detect that the page is invalid and simply return a 404.

Am I on the right path or is there a better way?

If I’m on the right path how do I detect the bad page name?

  • 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-05T01:36:33+00:00Added an answer on June 5, 2026 at 1:36 am

    I found what I’m looking for in another post and modified my method below.

    @GET
    @Produces("text/html")
    @Path("{page}") 
    public void showJSP(@Context HttpServletResponse response,
                        @Context HttpServletRequest request,
                        @PathParam("orderId") String orderId) throws ServletException, IOException {
        request.getRequestDispatcher(page + ".jsp").forward(request, response);
    }
    

    This gives me my 404 that I’m looking for and all of my services still work.

    If this is the ‘wrong’ way to do this I’m still open for ideas but for now it works.

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

Sidebar

Related Questions

I want to be able to invoke an SSIS package at will from a
I want to be able to email a report daily from a glpi database
Is it possible in php to return a specific row of data from a
I want to be able to return all of the parameters that are being
I want to be able to specify user specific conditions in a MAX() sql
This one is kinda specific. I want to be able to retrieve an integer
I have a textReader that in a specific instance I want to be able
I have a situation where I want to return an animated gif from an
I want to be able to grab keys/values from a cookie and use that
Given this structure.. I basically want to be able to take a list of

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.