0

java - restful service: I created a dynamic web page where I used @QueryParams over a few methods

for example, http://localhost:7001/students/get?id=1 will return the student's details with the id value of 1

Great...

I've built also a readme.html file that I'm trying to present once the client is accessing the web page localhost:7001/students = supposed to see a readme.html file....

My problem is (first of all) that I got no idea how things work in the web.xml file.

(second of all) my readme file wont show up!

I found the cause of the problem and it is in the <url-pattern></url-pattern>

Odd thing is that when I set it to <url-pattern>/*</url-pattern>

My functions work, for example, once I hit the URL http://localhost:7001/students/get?id=1 I get my output

But when I hit http://localhost:7001/students/ theres no readme, just blank screen :(

AND when I change the url pattern to - <url-pattern>students</url-pattern> for example

I can see my readme at the url - http://localhost:7001/students/

but my functions wont work I get a 404 error :(

my web.xml file:

   <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>students</display-name>
  <welcome-file-list>
    <welcome-file>readme.html</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

 <servlet>
    <servlet-name>students</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>students</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>students</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>

</web-app>

Thanks in advance for any reply, will really appreciate a solution, Iguana.

iguana
  • 77
  • 1
  • 9
  • I think this link can help to understand better how to do[click here](http://www.tutorialspoint.com/restful/restful_first_application.htm) – Abdelhak Nov 15 '15 at 10:24
  • I don't marked it as duplicated but the next time try to search the solution more deeply not post the Q – Abdelhak Nov 15 '15 at 10:34
  • Listen Abdel, in that thread, no answer was approved, and I can see why, the answers aren't showing how to manipulate the given code by the one who asked the question, nevertheless there was no answer approved. AND that thread wasn't helpful to me, thank you very much in advance, abdel – iguana Nov 15 '15 at 10:41
  • Just because an answer wasn't checked doesn't mean there isn't a solution. I am very careful when marking duplicates. I carefully read the question to make sure the problem can be solved with answers in the duplicate. Both of the top answers are solutions to your problem. If you edit your question with what you tried from the duplicate, I will try and help you figure out what you are doing wrong if it's not working for you. But I know _for sure_ that the solutions will solve your problem – Paul Samsotha Nov 15 '15 at 11:19

0 Answers0