Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP won't run with hard-coded IP (same as "localhost")  RSS feed

 
Mike London
Ranch Hand
Posts: 1441
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I have a JSP that calls another JSP (firefox 30) to display a pop-up message from the database. (All works fine if "localhost:8080" is used in the browser)

So, JSP1 calls JSP2, like this:

"window.open('/forums/b]<%=msgs[1]%>','width=400,height=300 resizable=yes');">

----

Now, if start the webapp like this: http://localhost:8080/theApplication

and then send a message to it using a separate browser tab (and thus am entering a message via a GET), it works. The popup message appears fine.

Yet, if I start the webapp using the IP of the machine (same as localhost): 10.0.1.15 the popup message does NOT appear (sending the message using the 10.0.1.15 here too). In fact for some reason JSP2 doesn't even run after being called from JSP1 in this case. Having looked at the code, there's nothing "localhost" hard coded and the app starts and behaves the same way (other than this pop-up display problem) regardless of localhost or the 10.0.1.15 startup method.

Looking in server.xml in Tomcat conf folder, it says: "<Engine name="Catalina" defaultHost="localhost">", yet I can't believe that's the issue. Just grasping here.

In all cases the message I send to the JSP via the GET is getting stored in the database.

When I step through JSP1, the message entered is present in both the localhost and 10.0.1.15 cases.

The issue is that when the "window.open('JSP2.jsp?<%=msgs[1]%>','width=400,height=300 resizable=yes');"> runs with the 10.0.1.15 case, nothing happens after that.

The problem seems like JSP2 is somehow not being resolved even though the app itself is unchanged.

Suggestions would be extremely welcome here!

Ideally, want to be able to run this app from a VM so using a remote IP will be required.

Thanks in advance,

-mike
 
Henry Wong
author
Sheriff
Posts: 23275
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Localhost resolves to the 127.0.0.1 address. This is different from the primary IP address of the machine, which is used to find the machine from another machine.

Henry
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not even understanding your syntax here: '/forums/b]<%=msgs[1]%>'

What's with the "b]"? What is "forums"? And why are you using scriptlet expressions in 2014?

In any case, all references should be server-relative, starting with the context path (see JspFaq) and the domain is implicit.
 
Mike London
Ranch Hand
Posts: 1441
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:I'm not even understanding your syntax here: '/forums/b]<%=msgs[1]%>'

What's with the "b]"? What is "forums"? And why are you using scriptlet expressions in 2014?

In any case, all references should be server-relative, starting with the context path (see JspFaq) and the domain is implicit.


Bear,

You're too funny.

Yes, you're right, this code was written in 2003 and I'm just moving it, while updating MySQL, Tomcat, and Java to another server. Please excuse the somewhat pseudo code copying and pasting.

Thanks,

-- mike
 
Mike London
Ranch Hand
Posts: 1441
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Localhost resolves to the 127.0.0.1 address. This is different from the primary IP address of the machine, which is used to find the machine from another machine.

Henry


Hi Henry,

Thanks for this.

OK, so this begs the question....How can I run code on another machine, say a VM, that I only reach via IP. Do I use a Machine Name or other construct?

I've created a VM with Tomcat, Java, and MySQL on an Ubuntu VM that I would like to deploy so people could just access it. Currently, I only really understand reaching it via its IP.

Could you please clarify how I can access it so the pop-up would resolve to (something like) "localhost" even though it's on another machine?

Thanks,

-mike
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But seriously, the syntax looks wonky. If the URL is bad, no JSP.

Should be something alongs the lines of: ${pageContext.request.contextPath}/whatever.jsp
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike London wrote:Could you please clarify how I can access it so the pop-up would resolve to (something like) "localhost" even though it's on another machine?

Already answered: you don't. Use server-relative addressing and let the host resolve automatically to the same machine.
 
Mike London
Ranch Hand
Posts: 1441
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:But seriously, the syntax looks wonky. If the URL is bad, no JSP.

Should be something alongs the lines of: ${pageContext.request.contextPath}/whatever.jsp


Sorry, it was just a typo when I copied and pasted into the forum message.

It all works and has for over 10 years (except when I now try the IP as I asked about).

Thanks,

- m
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the URL end up being in the browser? (View source) Looking at the server-side markup is rather uninformative.
 
Mike London
Ranch Hand
Posts: 1441
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:What does the URL end up being in the browser? (View source) Looking at the server-side markup is rather uninformative.


The URL in the browser is: 10.0.1.15/dispatcher

The dispatcher is the Servlet you go to after logging in at 10.0.1.15/theApplication

----

To do additional GET requests to simulate what the external program would do using POSTs, you would just:

10.0.1.15/dispatcher?parm1=foo&parm2=bar&parm3=etc

----

So, my question is that if I have an Ubuntu VM at address 10.0.1.17, how would I call it so the pop-up would work?

Everything else works fine with just the IP (the inet address).

Confusing.

Thanks,

-mike
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike London wrote:
The URL in the browser is: 10.0.1.15/dispatcher

That's what's in the HTML? Probably not. That's what we need to see. The server-side markup isn't what the browser sees. And what the browser sees is what's going to determine what URL is hit.

So what's the code end up as in the HTML?

if it's not a server-reltaive reference, it's wrong¹.





¹ Maybe too strong a word, but a non-server-relative URL is going to be finicky and fragile.
 
Mike London
Ranch Hand
Posts: 1441
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Mike London wrote:
The URL in the browser is: 10.0.1.15/dispatcher

That's what's in the HTML? Probably not. That's what we need to see. The server-side markup isn't what the browser sees. And what the browser sees is what's going to determine what URL is hit.

So what's the code end up as in the HTML?

if it's not a server-reltaive reference, it's wrong¹.





¹ Maybe too strong a word, but a non-server-relative URL is going to be finicky and fragile.


Well, after you go to "http://10.0.1.15:8080/theApplication" and Log in in the form shown, you then go to:

http://10.0.1.15:8080/theApplication/dispatcher, where you see the frame with various "divs".

Here's the HTML from that page (no IP address):



------------
Suggestions?

Thanks,

-- mike
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see the window.open call anywhere in that HTML.
 
Mike London
Ranch Hand
Posts: 1441
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:I don't see the window.open call anywhere in that HTML.


Sorry, Bear, there's really no way to get this since this page never actually .... "appears". It just is called by the JSP and runs.

The issue is that I don't understand how to otherwise call the local machine by it's IP Address listed in inet: the 10.0.1.15. (127.0.0.1 would probably work for the local machine, but how about a remote system?)

While the 10.0.1.15 IP seems to work for most of the messaging system, it's only the javascript command that calls the other JSP that fails.

Localhost works in all cases.

----

The goal is to be able to deploy a Ubuntu VM with the Tomcat, MySQL, and Java functionality prepackaged and just make calls to it from another machine.

If I can't use the VM's IP address - 10.0.1.22 (which, again, works for the majority of the app), then I'm not sure how to reference it by a "machine name" or whatever.

Hopefully there are suggestions in this direction as well.

Thanks,

-mike
 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the error log say?

EDIT: your dispatcher servlet does not handle page calls by parameter, right?
 
Mike London
Ranch Hand
Posts: 1441
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dieter Quickfend wrote:What does the error log say?

EDIT: your dispatcher servlet does not handle page calls by parameter, right?


Other than the "Address already in use" type errors when I forget to stop Tomcat so I can debug it using the IDE, the catalina.out is exception free.

The localhost log all has "200"s.

For the interactive portion of this web app (the GET), the dispatcher Servlet just takes the use to a web frame after he logs in.

Thanks,

-mike
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike London wrote:Sorry, Bear, there's really no way to get this since this page never actually .... "appears". It just is called by the JSP and runs.

The window.open has to appear somewhere. Otherwise how could it execute in the first place?
 
Mike London
Ranch Hand
Posts: 1441
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Mike London wrote:Sorry, Bear, there's really no way to get this since this page never actually .... "appears". It just is called by the JSP and runs.

The window.open has to appear somewhere. Otherwise how could it execute in the first place?


The window.open appears in HTML only code shown by "View Page Source", however when clicking the "View Page Info", all I see is the "http://10.0.1.15/theApplication/dispatcher".

I'm thinking this problem must somehow be related to the browser's sandbox. The same behavior happens in both Firefox 30 and the current version of Safari.

Really not sure what else to try.

- mike
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike London wrote:
The window.open appears in HTML only code shown by "View Page Source"

Last try: that is precisely what we need to see and the one thing you are not showing. The URL as it appears in the JavaScript on that page is the key to everything.

Really not sure what else to try.

Try showing what I've been asking for all along. You seem to be showing everything but the one thing we need to see.

(This all probably sounds testier than intended.)
 
Mike London
Ranch Hand
Posts: 1441
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Mike London wrote:
The window.open appears in HTML only code shown by "View Page Source"

Last try: that is precisely what we need to see and the one thing you are not showing. The URL as it appears in the JavaScript on that page is the key to everything.

Really not sure what else to try.

Try showing what I've been asking for all along. You seem to be showing everything but the one thing we need to see.

(This all probably sounds testier than intended.)


No worries, Bear. I understand your style (and your expertise).

Turns out that my mac's Firefox was the issue. Safari also works.

Dusting off and starting up Windows 7, installing the webapp, etc., everything works there. It also works across to the Ubuntu VM via IP.

I must have some strange issue or corruption in Firefox on the mac. Whatever.

----

I wasn't trying "not" to give you the information you requested; I just couldn't find it either in the debugger or the running HTML.

In any case, it looks like it's a non issue from a deployment point of view.

Thanks for your many thoughtful replies. :)

--mike
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, cool. Glad it's working.
 
Mike London
Ranch Hand
Posts: 1441
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:OK, cool. Glad it's working. :thumbup:


JR rocks! :)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!