This content has been marked as final. Show 15 replies
Try this code .
URL url = new URL("your current url ");
int port_no = url.getPort();
int def_port_no = url.getDefaultPort();
String url_val = url.toExternalForm()
"your current url" <-- I don't know my url
I want this code be dynamic
is it JSP ?
is it server side ?
request.getRequestURL() will get you the entire URL.
I am behind Alteon that change the port from 8001 to 80, so the client doesn't know about 8001, he uses 80.
Alteon = 80
Web server 8001
with request.getServerPort() I am getting 80
I want to I get the web server port => 8001
any idea ?
There's a configuration file (in xml ) format for the web server . from there we can edit different port numbers.
I have 1 web server (weblogic) with 3 instances working on it, using the same xml file.
The file is containing all these ports: 8001, 8010, 8011
But I need to know from which channel I arrived to this server.
well , Things are pretty easy if it's a weblogic server.
1) Login to Admin Console
2) Select Servers from the Home page . There it will show the names of currentlyrunning server( ie , examplesServer , cgServer,medRecServer ..etc)
3) Select the server you want to change the properties and it will show an editable page
from there we can easily change different port numbers
I am not asking how to configure nor how to check the configuration
I just want a JSP that will identify the port I am using automatically.
I'm not sure I completely understand your configuration, but does this get you what you want?
I couldn't managed to use "localPort", maybe I had a syntax problem.
This is the code that I am using:
<%@ page import="java.net.*" %>
<%@ page import="java.util.*" %>
//int port_no = request.getServerPort();
//List list = admin.getInstanceVariables(instance.getId());
// out.println("<b>Instance Name</b> = "+ admin.getInstanceVariables(instance.getId()) +"<br>");
out.println("<b>Host Name</b> = "+ java.net.InetAddress.getLocalHost().getHostName()+"<br>");
out.println("<b>Host Address</b> = "+ java.net.InetAddress.getLocalHost().getHostAddress()+"<br>");
out.println("<b>URL</b> = "+ request.getRequestURL() +"<br>");
out.println("<b>Port</b> = "+ request.getServerPort() +"<br>");
My previous example was just basic JSP EL. You can try this instead:
<%= request.getLocalPort() %>
cannot resolve symbol
symbol : method getLocalPort ()
location: interface javax.servlet.http.HttpServletRequest
out.print(String.valueOf( request.getLocalPort() ));