The first issue I encounter is when I try to use “Jetty At Path” in the run configurations (I have Jetty V 9.4.28), I encounter this problem “java.lang.NoSuchMethodException: addBefore”. I have tried googling it, but nothing came up. When I use “Jetty Provided By Launcher Plugin (Jetty 9.3)” the server runs fine.
The second issue I have been encountering is this:
Up until the POST request section, everything has run smoothly. But unfortunately every time I attempt the POST request submission, the output never gets displayed.
For example, the post request from “index.html” in the “GreetingWebApp” (location: GreetingWebApp/index.html) should display the submitted “name” value at a dynamic location as generated by the servlet and referenced by the web.xml file at “/hello” but I always encounter a 404 error and it is showing that it’s attempting to reach the “/hello” display at “http://localhost:8080/hello” which is outside of the “http://localhost:8080/GreetingWebApp/” domain…
Do you have any idea what the problem might be? I have tried everything I can think of, but nothing seems to work, and I have simply copy/pasted your code into my files, so I’m pretty certain it’s not a manual error regarding syntax or anything like that.
Unfortunately the server tutorials are in need of an update, so I’m not super surprised that parts of them are breaking. I’m planning on updating them later this year (after I finish with the intro p5.js tutorials), but let me try to at least get you unstuck for now.
In the meantime, it sounds like the problem might just be an incorrect URL somewhere. What code are you using that causes it to request the /hello URL? Can you maybe change that to /GreetingWebApp/hello or whatever URL you do have on your server?
I think I followed the link you provided for downloading Jetty, but the version I have appears to be an up-to-date version (9.4.28v20200408) as opposed to the v9.3 that’s provided by the Eclipse plugin
I just tried setting the “action” attribute of the form to “/GreetingWebApp/hello” and I also updated the xml to the url-pattern “/GreetingWebApp/hello” and that appears to still encounter the same 404 issue.
I will keep trying to figure it out and if I find a solution, I’ll let you know what I come up with. Otherwise, I will patiently wait for your updates. Thanks again, this is an amazing resource!
Ah that makes sense, I’m glad you got it figured out!
What you use for the URLs depends on your setup, and I don’t think I was very consistent when I originally wrote the tutorials. One of the things I need to do is go back and use one approach for everything. I’ll probably get rid of any mentions of sub-projects and stick with only using one top-level server, so then you don’t have to worry about this kind of thing.
Additionally, the same above discussion about using “/ChatWebApp/chat” in the form’s “action” attribute, and in the Servlet’s response.sendRedirect () function works for the ajax material as well… and in the request.open (“Get”, “xxxxx”) the “xxxx” should also be set to “/ChatWebApp/chat”
One other thing that would be a tremendous help, for me at least, is if you cover ajax requests with the ip address as the host, rather that simply localhost. This is the next item I’m trying to figure out…
My code in php for this looks something like this:
I’ve tried doing this similar approach with the Java server tutorials, but I haven’t been able to figure out how to get it work with my ip address as the host rather than “localhost”… maybe this is something you cover in the later material for the Java server tutorial (I’m not sure because I haven’t gotten there yet)… but if it’s not something that you’ve already covered, is it something you might be willing to cover in the future?
Just out of curiosity, what does using the IP address get you?
For what it’s worth, I only ever use localhost for development and testing. I’ve never used my local machine as a live server. For that, I’ve always deployed to something like AWS or Google Cloud.
In general I would use URL paths relative to the top level, in other words URLs that start with a / so they work both locally and when they’re deployed to the live server.
But if you’re trying to use your local machine as a live server, you’ll probably need to jump through a few more hoops. (That’s one of the reasons I haven’t gone in that direction.)
using the ip address allows you to develop/test locally not just with the browser application but also with mobile apps using the same server.
in my experience, i was never able to get my mobile app to connect with the same server as my browser client, when I used “localhost”… there could be something else I was doing wrong, though, which may have been preventing the “localhost” implementation from working…
but when I’ve used the ip address, i was able to get the mobile app and the browser to connect to the same server code…
and you’re definitely right about needing to jump through a few extra hoops. the main one i’ve encountered is a firewall. The WindowsDefender Firewall is enabled by default since windows 8, i believe, and for awhile when I first started trying to test connecting my mobile app with the same server code as my browser app, the firewall running is what was getting in the way, but once I disabled the firewall and made sure my mobile device is on the same network as the hosting machine, then I was able to connect to the server code using the ip address, but i recall not being able to connect with “localhost” (it’s been awhile, though, so maybe i’m remembering something not quite right, because i have mostly been focused on the browser app implementation once i figured out how to establish just a basic connection with the mobile app to the same server)
Yeah that sounds pretty annoying! I’ve dabbled very briefly with trying to access my local machine from a mobile device just for testing, but honestly I don’t trust myself to maintain a secure enough server that it wouldn’t put my personal machine at risk, so I’ve always gone with a cloud solution for my “real” servers.
But if you want to go with the IP address route, you should “just” be able to add your IP address (and possibly the port) in front of any of the URLs that currently start with a /. If that doesn’t work, it’s probably a network configuration problem, which I try to stay very far away from.
ohhhhh maybe it was leaving out the port that was the problem… I haven’t had to include that in testing my php code, so I didn’t even think to include that for the Java approach…
Haha, yeah, you’re definitely right! It’s safer to NOT be doing it with my ip address on my local machine… and I’m honestly to the point where I’m nearly ready to deploy my “beta” for the php implementation… I just was doing it at the time because I was still in school and didn’t have any money for hosting fees haha… but I should really look into hosting for real at this point
For what it’s worth, I’ve found that Google Cloud is actually pretty cheap, as long as you stick to the free stuff (features like Google Cloud SQL are very expensive, but you can just not use it). I think I end up paying something like 5 bucks a month for the random projects I have out there on the internet, but then again none of them are getting much traffic. If I was going to spin up a new server, that’s probably what I’d do.
But I don’t want to talk you out of playing with your own server. I personally get frustrated by that stuff, but if you’re into it, I say go for it!
Thanks! Yeah, once I hit that section (Hosting on AWS and Google Cloud) in your tutorial, I will definitely look into it.
For the goal I’ve been pursuing, long-term would probably be best running my own server (because of hosting fees due to scale)… but for now hosting on another service is probably ideal…
Also, you were right. Including the port for the ip address implementation resolved it
Haha I never would have even considered including the port, because PHP doesn’t require it… not sure why that is, do you have any idea? I guess it just assumes (or maybe forces?) you’re using port 8080?