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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T08:18:37+00:00 2026-05-17T08:18:37+00:00

I ve created a sample REST web service which writes some data in a

  • 0

I ve created a sample REST web service which writes some data in a xml file. Now I have hard coded the path where the xml file is to be written. I want to know how to declare that local path of the file in web.xml file as servlet parameter and how to get the path from there and use it in codebe . Also I need to create the WAR file for the service which needs to deployed in tomcat. This war file should take that parameter from the web.xml file. I used eclipse IDE to develop the web service. Can anyone tell me how to do the above things ?

Here I have attached the servlet code present inside the web.xml file.

<servlet>
  <servlet-name>Jersey REST Service</servlet-name>
<servlet-class>
  com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class>
<init-param>
    <param-name>com.sun.jersey.config.property.packages</param-name>
    <param-value>com.sample.service</param-value>
  </init-param>
  <init-param>
    <param-name>filepath</param-name>
    <param-value>filepath value</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
  <servlet-name>Jersey REST Service</servlet-name>
  <url-pattern>/api/*</url-pattern>
</servlet-mapping>

com.sample.service is the package where I have my Rest web service class.

  • 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-17T08:18:37+00:00Added an answer on May 17, 2026 at 8:18 am

    Assuming you created this as a Dynamic Web project in Eclipse, just right-click on the

    project name, > Export > WAR file

    and fill in the details it asks for.

    In your web.xml, you can define your filepath as below

    <servlet>  
    <servlet-name>MyServletName</servlet-name>  
    <servlet-class>com.mycompany.MyServlet</servlet-class>  
    <init-param>  
    <param-name>filepath</param-name>  
    <param-value>D:\hard-coded-path.xml</param-value>  
    </init-param>  
    </servlet> 
    

    *Updated with correct answer as per comments *

    You’re getting the NullPointerException on getServletContext().getInitParameter(“filepath”) because the Context is not injected into the web service method.

    And in your web service, use this code to get the path and write to it using the @Context annotation

     @GET
    @Produces("text/plain")
    public String doStuff(@Context ServletConfig sc) {
    
    
    
       String xmlpath = "Output filepath is: " + sc.getInitParameter("filepath");
        return xmlpath;
    }
    

    See here for usage and examples of @Context

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

Sidebar

Related Questions

I have created a REST Web Service that in all other ways is working
I have a REST web-service interface that calls-down to a service layer which orchestrates
I have created a simple Northwind's Product REST Web Service in WCF at /Northwind/Product
I have created a REST web service using WCF and use HTTP Post Method.
I have a problem regarding xml calling to REST web service, I have to
i have created a Java Restful Web service . Now i want to access
I have created a sample report with crystal report 10. Now, I wanna to
I have developed a sample WCF REST service that accepts that creates an Order
I have constructed a simple Rest service using ServiceStack (which is brilliant), that returns
I have an application which consists of SOAP and REST web services and a

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.