如何在没有URL中的应用程序上下文的情况下使用Weblogic(12 C)? [英] How can I use Weblogic (12 C) without the application context in the URL?
问题描述
我正在开发一个需要Weblogic服务器的Web项目,并且在部署(在我的Macbook Pro上)之后我可以查看该站点的唯一方法是将应用程序名称指定为整个站点的前缀。例如
I am working on a web project that requires Weblogic server and the only way I can view the site after deploying (on my Macbook Pro) is by specifying the application name as a prefix to the entire site. E.g.
http://localhost:7001/myapp-weblogic/
这打破了大量使用根URL访问资源的样式和JavaScript代码(例如/images/example.png)
This breaks a ton of styling and JavaScript code that access resources with root URLs (e.g. /images/example.png)
虽然我可以通过编程方式将/ my-app添加到.jsp中的内容中,但我无法在.css文件中执行此操作。
While I can programmatically add "/my-app" to content in a .jsp, I can't do that in my .css files.
我尝试在Weblogic> console> Environment> Servers> myserver > Protocols> HTTP中设置默认WebApp上下文根: - 但是没用。
I tried setting the "Default WebApp Context Root:" in Weblogic > console > Environment > Servers > myserver > Protocols > HTTP - But that did not work.
这看起来应该是这么简单。在IIS中,我只需在我的本地主机文件中添加一行,并将主机名添加到我的IIS容器中 - 总共大约需要42秒。
This seems like it should be such a simple thing. In IIS I would simply add a line to my local hosts file and add the host name to my IIS container - taking me a grand total of about 42 seconds.
127.0.0.1 myapp.local -> Let's me view my site at http://myapp.local
提前感谢您的任何见解!
Thank you in advance for any insight!
更新!!
我终于把事情搞定了。其中一些非常特定于我的设置,但希望仍然对其他人有用。
UPDATE!! I finally got things working. Some of this is very specific to my setup, but hopefully still helpful to others.
为了让它正常工作,我需要做3件事和另外一件事: / p>
To get it working I needed to do 3 main things and one other related thing:
- 在Weblogic中设置服务器的默认应用程序
- Set the default application for the server in Weblogic
- 在本地服务器上,转到到控制台并登录
- 转到:Weblogic> console>环境>服务器> myserver >协议> HTTP
- 将默认WebApp上下文根目录:设置为/+您的应用程序(例如/ myapp)
- On your local server, go to the console and log in
- Go to: Weblogic > console > Environment > Servers > myserver > Protocols > HTTP
- Set the "Default WebApp Context Root:" to "/" + your application (e.g. "/myapp")
- 在MyEclipse中打开项目,右键单击项目并选择属性
- 展开 MyEclipse并选择Web并将Web Context-root设置为/
- 此文件应位于项目的WEB-INF文件夹中
- Sav e文件并构建应用程序
- 重新部署应用程序 - 您可能还需要重新启动服务器
将我的本地路径变量设置为/
所以我要做的另一件事就是设置路径变量我引用了/。当您请求路径(request.getContextPath();)时,它不会在路径前加上/,如果您尝试使用类似< c:url context =$ {_ path}的内容
如果_path变量不以/开头,它将引发异常。
Setting my local path variable to "/"
So another thing I had to do was set a path variable i was referencing to "/". When you request the path (request.getContextPath(); ) it does not prepend the path with a "/" and if you try to use something like <c:url context="${ _path }"
if the the _path variable does not begin with a "/" it will throw an exception.
最后一点是我在使用其他人的代码时遇到的问题。
That last bit was something I encountered from working with someone else's code.
推荐答案
在application.xml中指定以下设置
In application.xml specify the below setting
<web>
<web-uri>yourweb.war</web-uri>
<context-root>/</context-root>
</web>
现在你可以在没有上下文根的情况下拨打电话
Now you can make a call without context root as
http://localhost:7001/
这篇关于如何在没有URL中的应用程序上下文的情况下使用Weblogic(12 C)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!