Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
545 views
in Technique[技术] by (71.8m points)

java - How can I use Weblogic (12 C) without the application context in the URL?

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/

This breaks a ton of styling and JavaScript code that access resources with root URLs (e.g. /images/example.png)

While I can programmatically add "/my-app" to content in a .jsp, I can't do that in my .css files.

I tried setting the "Default WebApp Context Root:" in Weblogic > console > Environment > Servers > myserver > Protocols > HTTP - But that did not work.

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.

To get it working I needed to do 3 main things and one other related thing:

  1. Set the default application for the server in Weblogic
    1. On your local server, go to the console and log in
    2. Go to: Weblogic > console > Environment > Servers > myserver > Protocols > HTTP
    3. Set the "Default WebApp Context Root:" to "/" + your application (e.g. "/myapp")
  2. Set the context-root of the project in MyEclipse
    1. With your project open in MyEclipse, right-click on the project and select properties
    2. Expand "MyEclipse" and choose "Web" and set the Web Context-root to "/"
  3. Set the value of context-root in the project weblogic.xml file to "/"
    1. This file should be located in the WEB-INF folder of your project
    2. Save the file and build the app
    3. Redeploy your app - you may need to restart your server too

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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/

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...