简体   繁体   English

如何在Java EE中将主页映射到“应用程序的根目录”?

[英]How to Map home page to “root of application” in Java EE?

Set-Up- I have a JSP - index.jsp and a servlet indexController. 设置-我有一个JSP-index.jsp和一个servlet indexController。 indexController forwards request to index.jsp. indexController将请求转发到index.jsp。 Execution of index.jsp without execution of indexController is not desired. 不执行indexController而不执行index.jsp是不希望的。

Requirements- 要求-

  1. 'www.mysite.com' should be served by indexController/index.jsp “ www.mysite.com”应由indexController / index.jsp提供
  2. Any request with invalid url should get redirected to 'www.mysite.com'. 网址无效的任何请求都应重定向到“ www.mysite.com”。
  3. 'www.mysite.com/index.jsp' should get redirected to 'www.mysite.com'. “ www.mysite.com/index.jsp”应重定向到“ www.mysite.com”。

My Solution - 我的解决方案-

  1. Map indexController to "/" - I read that this is overriding 'default servlet' and I want to avoid that. 将indexController映射到“ /”-我读到它覆盖了“默认servlet”,我想避免这种情况。
  2. Map 'index.jsp' in welcome-file-list: I don't need to explicitly map it science 'index.jsp' is there, it will be automatically taken as welcome file. 将“ index.jsp”映射到welcome-file-list:我不需要显式映射它,因为“ index.jsp”已经存在,它将被自动作为欢迎文件。 Doing this doesn't execute indexController. 这样做不会执行indexController。 Moreover invalid urls are 'forwarded' not redirected to welcome file. 而且,无效的URL被“转发”,而不重定向到欢迎文件。
  3. Map error page to home page- This is cheating with yourself. 将错误页面映射到主页-这是在欺骗自己。 I don't want to hide errors. 我不想隐藏错误。
  4. Use two servlets. 使用两个servlet。 One with "/*" mapping, which redirects everything to 'mysite.com'. 一种带有“ / *”映射的映射,它将所有内容重定向到“ mysite.com”。 Second mapped to ""(empty) that actually serves request. 第二个映射到实际为请求提供服务的“”(空)。 - Some mysterious issues here(yet to figure out) -这里有一些神秘的问题(还需要弄清楚)

I think, everyone wants to achieve same functionality for their home screen and there are many questions at stackoverflow with similar problems. 我认为,每个人都希望为自己的主屏幕实现相同的功能,并且在stackoverflow上存在很多类似问题。

Is there any standard solution which solves problem for once and for all. 是否有任何标准解决方案可以一劳永逸地解决问题。


Edit:- There were only 7 views in more than 30 mins. 编辑:-在超过30分钟内只有7个视图。 Removed GAE tag, to attract more views. 删除了GAE标签,以吸引更多观看次数。

Simply put a web server before your app server and you can map any URL to any application/page. 只需将Web服务器放在您的应用服务器之前,您就可以将任何URL映射到任何应用程序/页面。 Also don't publish an app server directly. 另外,请勿直接发布应用服务器。 Are you using Tomcat I presume, so you probably deployed ROOT application, right? 我假设您正在使用Tomcat,因此您可能已部署了ROOT应用程序,对吗? (you should go with the web server anyway) (无论如何,您都应该使用网络服务器)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM