Making the website welcome page a servlet

Can I make a website welcome file a servlet? If so, how? I tried something like:

<welcome-file-list> <welcome-file>FilterForwarded</welcome-file> </welcome-file-list> <!-- FilterForwarded is a servlet --> 

During deployment, I see no errors, but when I try to open abc.com, I get a message from the browser that it cannot connect to this website. Why is this so?

I want someone to visit the website, I should be able to store the public IP address of the client. To do this, I wrote a filter, which after accepting IP passed it to the servlet (from there I could update the logs). After saving the IP address, the client is automatically redirected to index.jsp. Is there any way to achieve this?

EDIT:

  <servlet-mapping> <servlet-name>FilterForwarded</servlet-name> <url-pattern>/FilterForwarded</url-pattern> </servlet-mapping> 

This is the mapping defined in web.xml. When I use /FilterForwarded in the welcome file, I get this message when I try to deploy: Bad configuration: the greeting files should be relative: / FilterForwarded

From the magazines:

 com.google.apphosting.utils.config.AppEngineConfigException: Welcome files must be relative paths: /FilterForwarded at com.google.apphosting.utils.config.WebXml.validate(WebXml.java:125) at com.google.appengine.tools.admin.Application.<init>(Application.java:150) at com.google.appengine.tools.admin.Application.readApplication(Application.java:225) at com.google.appengine.tools.admin.AppCfg.<init>(AppCfg.java:145) at com.google.appengine.tools.admin.AppCfg.<init>(AppCfg.java:69) at com.google.appengine.tools.admin.AppCfg.main(AppCfg.java:65) 
+6
source share
1 answer

If you map the filter to / *, you should be able to intercept all requests and then register the IP address there.

Or is your requirement only to register the client IP address for the landing page?

If so, you can change the default servlet for the Servlet container, but remember that this will change the default servlet for all requests that do not match the mappings in your web.xml.

 <servlet-mapping> <servlet-name>FilterForwarded</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> 

A more complex but potentially better solution is to run your Java web container using a web server and use the rewrite rules for the proxy for your server servlets. This method will mean that you can manage the servlets that you access for your landing page without overriding the default servlet for all inappropriate requests. This may be redundant for your problem.

+4
source

Source: https://habr.com/ru/post/924842/


All Articles