SHARE
TWEET

Untitled

a guest Jun 18th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @WebServlet(name="fooServlet", urlPatterns="/foo")
  2. public class FooServlet extends HttpServlet
  3. {
  4.     @Override
  5.     protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  6.         String flip = getInitParameter("flip");
  7.         resp.getWriter().println("<html>" +
  8.             "<head><title>" + getServletName() + "</title></head>" +
  9.             "<body>From " + getServletName() + ": " + flip + "</body>" +
  10.             "</html>"
  11.         );
  12.     }
  13. }
  14.      
  15. <servlet>
  16.     <servlet-name>fooServlet</servlet-name>
  17.     <init-param>
  18.         <param-name>flip</param-name>
  19.         <param-value>flop</param-value>
  20.     </init-param>
  21. </servlet>
  22.      
  23. [hostname]/my-service/api?myParameter1=myValue1&myParameter2=myValue2
  24.      
  25. @WebServlet(
  26.         name = "MyServletName",
  27.         description = "MyDescription",
  28.         urlPatterns = {"/my-service/api"},
  29.         initParams={
  30.             @WebInitParam(name="myParameter1", value="Not provided"),
  31.             @WebInitParam(name="myParameter2", value="Not provided")
  32.         }
  33.     )
  34. public class MyServlet extends HttpServlet {
  35.  
  36.  
  37.     @Override
  38.     public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException
  39.     {
  40.  
  41.       String parameter1 = request.getParameter("myParameter1");  
  42.       String parameter2 = request.getParameter("myParameter1");
  43.  
  44. ...
  45.      
  46. public static String SOME_STRING= "stringVal";
  47.      
  48. import static something.Constants.SOME_STRING;
  49.  
  50. @WebInitParam(name=SOME_STRING ,.....)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top