Reputation: 35
I am currently developing a servlet which returns a lot of data to a given ID. It is called under the URL
localhost:8080/RTC_W/api?id=123
and has no special path given in the source code. My web.xml maps it as followed:
<servlet-mapping>
<servlet-name>APICaller</servlet-name>
<url-pattern>/api</url-pattern>
</servlet-mapping>
It is called by a welcome file, which looks like this (relevant part only) and offers a little box to type in the ID:
<body>
RTC W Front End
<form action="/api" method="get">
Work Item ID:<br>
<input type="text" name="id" value=""><br>
<input type="submit" value="Submit">
</form>
</body>
as you can see, form action should call path /api where the servlet is located. The URL called is wrong though, it always calls
localhost:8080/api?id=123
So the /RTC_W/ is missing. If I add it to <form action="RTC_W/api" method="get">
, this URL gets called:
localhost:8080/RTC_W/RTC_W/api?id=123
So the path is called twice. What am I doing wrong?
Upvotes: 1
Views: 105
Reputation: 6533
<form action="api" method="get">
This is what you should use.
When a URL starts with /
it is always an absolute URL, i.e. appended right after the <hostname>:<port>
If a url does not start with /
it will get appended to the current URL.
Upvotes: 1