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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:30:42+00:00 2026-05-23T02:30:42+00:00

I created a JSP Tag Handler class in Java and defined it in XML

  • 0

I created a JSP Tag Handler class in Java and defined it in XML in the .tld file.
In my .jsp file, I declared the tag and defined its attributes – one of them being the path to the file that is to be read.

When passing the virtual path to the ServletContext’s getRealPath method, it returns this weird, non-existent file path. When I tried to just simply pass the real file path outright to the tag, it gives me some weird “access denied” message.

What makes this more confusing to me, is that I managed to accomplish the same thing without tags but having the HttpServlet handle the work all by itself. The HttpServlet has no problems with carrying out this task, but the jsp tag class can’t and I don’t know why.

Can someone with any experience in IO tasks and writing custom java tags help me on this one?

Update:

Here’s what the file directory of my website looks like (where “..” represents that there are additional files and folders within that directory that aren’t shown). Also note, that using “<” and “>” causes the text to disappear on this forum, so I couldn’t use them to specify a general label for the directory but that whatever is in all caps isn’t actually the name of the directory:

ROOT/Accounts/.. (location of
Login.jsp)

ROOT/data/.. (location of
datafile to be read)

ROOT/.. (other
folders)

Since, the project is named “Epsilon” in Eclipse, the resulting URL for any one of these directories is:

http://localhost:8080/Epsilon/Accounts/..

http://localhost:8080/Epsilon/data/..

http://localhost:8080/Epsilon/..

In the jsp file, I define it as follows:

<tags:HeaderContent path="/data/header.markup" id="topMenu"></tags:HeaderContent>

*Note the attribute “path”, because it’s really important!

In the Java class, in the doStartTag() method, I have the following:

        ServletContext context = pageContext.getServletContext();
        JspWriter out = pageContext.getOut();
        String realPath = context.getRealPath(context.getContextPath()
                + path);
        out.println(getHeaderContent(realPath).toString());

The context.getContextPath() and the path variables both end up being

“/Epsilon/data/header.markup”.

I pass those two concatenated strings as arguments for the ServletContext object’s getRealPath method. What the realPath String results in is the following:

“Z:\Dropbox\workspaces\Sites.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\Epsilon\Epsilon\data\header.markup”

I really don’t know why it returned the metadata folder, but this is not where the file is actually located. And, as I already mentioned earlier, the HttpServlet didn’t encounter this same problem but the JSP tag’s class did.

  • 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-23T02:30:42+00:00Added an answer on May 23, 2026 at 2:30 am

    You should not include the context path in the getRealPath() call. The context path is only represented in URLs and not in the local disk file system. The getRealPath() expects a relative local disk file system path relative to the webcontent root.

    context.getRealPath(path);
    

    As to why it’s located in Eclipse’s metadata folder, that’s just because you deployed and run this from inside Eclipse. This should not harm, this is exactly what the getRealPath() should be taking care of.

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

Sidebar

Related Questions

I'm using JBOSS 4.0.2 with JSP 2.0. I have created a TAG file with
I created a ( JSP-based) custom EL function to use in the rendered tag.
I have created a jsp file, with a simple table on it. I would
My JSP-application requires some configuration; so I created the Settings class which is a
I just created a .jsp file in my google app engine project. How to
I want to create a custom tag library but in the handler class I
I have a jsp file were the db connection is created and queries can
I'm trying to create a custom JSP tag that would take an array object
In a JSP page, I created a <h:form enctype=multipart/form-data> with some elements: <t:inputText> ,
I created a WebApplication in NetBeans. It has a JSP page and a webservice.

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.