The point of annotations is really to allow you to accept parameters more flexibly (even if your parameters will be constant values).
If you need constant values for your parameters, you could define these somewhere, then construct a URL that includes your values in a querystring. You can then use that URL to make an HTTP request to your service. For example, you could construct a URL that looks like this:
[hostname]/my-service/api?myParameter1=myValue1&myParameter2=myValue2
You can then use this URL to make a GET
request to your service, which would look like this:
@WebServlet(
name = "MyServletName",
description = "MyDescription",
urlPatterns = {"/my-service/api"},
initParams={
@WebInitParam(name="myParameter1", value="Not provided"),
@WebInitParam(name="myParameter2", value="Not provided")
}
)
public class MyServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException
{
String parameter1 = request.getParameter("myParameter1");
String parameter2 = request.getParameter("myParameter1");
...
@WebInitParam
is only being used to define default parameter values in case values for those parameters aren't supplied. So, if you have constants somewhere that you use to construct a URL that you then use to make an HTTP request, you can achieve what you're looking for.