0

Retrieving the full context path of my web app (Not the real paht)

asked 2009-06-17 14:55:20 +0800

gyowanny gravatar image gyowanny
283 1 2 6

updated 2009-06-17 15:19:52 +0800

Hi Folks,

Currently I'm using the following method to retrieve the context path of my app:

public static String getApplicationContext(HttpServletRequest req){
       String protocol = "http";
       String server = req.getServerName();
       String port = ""+req.getServerPort();
       String context = req.getContextPath();
       String webContext = protocol+"://"+server+":"+port+context;
  	
       return webContext;
}

obviously, this method returns something like: http://myhost:8080/myApp/

Is there any method/way in zk that could give me the same information?

Thank you

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2009-06-17 15:38:47 +0800

YamilBracho gravatar image YamilBracho
1722 2

I think this could help (Executions.getCurrent().getContextPath())

link publish delete flag offensive edit

answered 2009-06-17 16:03:32 +0800

gyowanny gravatar image gyowanny
283 1 2 6

Ymail,

Thanks for your answer but this returns just /myApp

link publish delete flag offensive edit

answered 2009-06-17 16:11:00 +0800

YamilBracho gravatar image YamilBracho
1722 2

Well, you have another methods in that class like:
- getServerName()
- getServerPort()

So you can write something as you did:

public static String getApplicationContext(){
   StringBuilder sb = new StringBuilder(1024);
   
   sb.append("http://");
   sb.append(Executions.getCurrent().getServerName()).append(":");
   sb.append(Executions.getCurrent()..getServerPort());
   sb.append(Executions.getCurrent().getContextPath());
   return sb.toString();
}

link publish delete flag offensive edit

answered 2009-06-17 17:24:03 +0800

gyowanny gravatar image gyowanny
283 1 2 6

Yes, that's what I figured out

the same thing but in a better way.

I just wonder why there is no method to handle this?
**Maybe because just me want this

Thanks again

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-06-17 14:55:20 +0800

Seen: 405 times

Last updated: Jun 17 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More