Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of all available servlets?

Tags:

java

servlets

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).

like image 218
Fernando M. Pinheiro Avatar asked Oct 27 '10 20:10

Fernando M. Pinheiro


People also ask

What is used for get () method in servlet?

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.

What method can be used to retrieve all the parameter values being sent as part of the request by the client?

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.

What are the methods that a servlet can use to get information about the server?

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.

Which method is used to access HTML variable in servlet?

Use getAttribute() of servlet context to find value of application scope variable. If the specified variable does not exits then it returns null.


2 Answers

Map<String, ? extends ServletRegistration> servletRegistrations = request.getServletContext().getServletRegistrations();

It will help you.

like image 184
Timur Samkharadze Avatar answered Sep 18 '22 00:09

Timur Samkharadze


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.

like image 40
kukudas Avatar answered Sep 18 '22 00:09

kukudas