Is it possible to get a list of all available servlets in an app?
I'm writing a web application that will expose a lot of servlets and I want to use HttpUnit to test each one to see if it is returning (or not!).
As lot of it will return a simple XML response, it would be really helpful not to write a test case for each one, only verify that it is working (a database change has not stopped this servlet to work, for example).
The doGet() method in servlets is used to process the HTTP GET requests. So, basically, the HTTP GET method should be used to get the data from the server to the browser. Although in some requests, the GET method is used to send data from the browser to the server also.
If there's any chance a parameter could have more than one value, you should use the getParameterValues( ) method instead. This method returns all the values of the named parameter as an array of String objects or null if the parameter was not specified.
Because these methods are attributes of ServletContext in which the servlet is executing, you have to call them through that object: String serverInfo = getServletContext(). getServerInfo(); The most straightforward use of information about the server is an “About This Server” servlet, as shown in Example 4.3.
Use getAttribute() of servlet context to find value of application scope variable. If the specified variable does not exits then it returns null.
Map<String, ? extends ServletRegistration> servletRegistrations = request.getServletContext().getServletRegistrations();
It will help you.
Don't think there is something out of the box. However you could write a small programm which parses your web.xml to gain the needed information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With