• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error servlet Port

 
fernando scalia
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm trying to access a Servlet by a form on a JSP page:


My web.xml:


If I try: www.primecorretoraseg.com.br:8080/contato it works!
By the JSP, i got a 404 error and also www.primecorretoraseg.com.br/contato get the same 404 error.

My question is, Why only with the ":8080/" it works, if I'm using a relative path? And how to fix it?

Some help will be appreciated.
tks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has nothing whatsoever to do with code. Tomcat is configured to run on port 8080.

If that's not what you want, change it in the Tomcat configuration. Ne aware that it takes privs to run on port 80.
 
fernando scalia
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marshal, tks for the reply.

My problem is that my code is hosted on a third part server and they told me that the shared tomcat is using the 8080 port, so, I can't change it.
So, I asked myself, how do other people who hosts on these server do, to access their Servlets... by the same way, i can access mine, but I don't know how.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fernando scalia wrote:how do other people who hosts on these server do, to access their Servlets

They use hosting providers with more reasonable support.

In all seriouness, they can change Tomcat to run on port 80 and it will serve all requests. Port 80 is the default, so one does not have to specify it on URLs.

Or, many hosting sites front their servlet container with the Apache Web Server, which runs on port 80. When a request for the servlet container comes in, a module in the Apache Server routes it to the servlet container.

If they aren't going to do either of these, you'll either need to specify port 8080 on all requests, or find a better provider.
 
Paul Clapham
Sheriff
Posts: 21550
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have regularly tested web applications against servers which are listening on a non-standard port. And I never ever had to hard code a port number anywhere in URLs in the web pages. So you must be doing something wrong somewhere. Unfortunately with what you posted I have no idea what it might be.

I suggest that before you click on that link, you hover over it to see what your browser thinks it points to.
 
fernando scalia
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault, that's what I think... and that's what I'm lost

Paul Clapham, can you please help me giving an exampleof a JSP form calling a Servlet, that you usually use in your tests? Can be somethig simple...
if you can, or other reader, please send it to my e-mail fernando.scalia@gmail.com

I really appreciate the answers, because I really need to finish this thread.

tks a lot.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All URLs in a web-app that reference other resources in the web app should be server-relative; that is, starting with the context path. As Paul said, the port number should never need to be specified anywhere within the code.
 
fernando scalia
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can be some apache configuration on the server??

well... i've email them asking the last time for a solution and if they don't help me, i'll be migrating my website to another server, a serious one, as someone said above.

i really appreciate the answers becouse I was thinking that the problem is with my app.

tks again.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You did not answer the questions: do you have the port number hard-coded in any URLs within your app?
 
fernando scalia
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, Bear, I don't have the port number hard coded, but, www.primecorretoraseg.com.br:8080/contato works. You can try.

The server's support peopele told me to use ":8080" hard coded, witch shall be wrong as we saw on the posts above.

Me form cals only "/contato" as I posted the code, making the URL without the port number (www.primecorretoraseg.com.br/contato) and these way, don't works (404 error).

Sorry about my bad english anyway and thanks for the reply. If there is something that I din't clarify, feel free to ask.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The port number never needs to appear in your code. You simply need to specify the 8080 when typing into a browser to access the web app.

Is there a reason you don't want to do this? Or is it because you have customers/clients who won't remember to use the 8080?
 
fernando scalia
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The second option. It is not good to tell my address everytime with the 8080 port, because customers usually don't know about "ports" and "servers", in most cases, they never heared about it.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case I would agree that if your hosting provider cannot give you access through port 80, you need to find a better provider.
 
fernando scalia
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After analize all of these answers, to fiz my problem temporarily, I'm gonna put a redirect index.jsp to check if the request come with the 8080 port. If it comes without, i'm gonna redirect to the same address with the port.
It will workaround my problem and my website gonna "work" until i find a better hosting service.

Again, i would like to thank the answers, it really helped me.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you cannot receive requests on port 80, how are you you going to check if the request has a port or not?
 
fernando scalia
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My JSPs are successfully accessed.
It means that the 80 ports request redirects to my server and the JSPs are shown.
Inside the JSP, I have the Form described that cals the Servlet and these last request cannot be made.

So, when I receave the frist request, on port 80 and the index.jsp is shown, I'll check if the request came from 80 or 8080 port, an then I'll redirect.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now you've got me really confused. If you can receive request correctly on port 80, what is the problem in the first place?

If you can access the JSPs in a web app, and cannot access the servlets, then there is something very wrong with your app.

Redirecting around is not a solution, it's a poor attempt at a bandaid.
 
fernando scalia
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with you, and thats what i was trying to find out. What's the problem with my app, if the servet mappings are correct?
Have you try to access the website?
try it, first without 8080 an than with it. You'll see that the forms could not call the servlet on the frist attempt.

My WEB.XML was posted on the frist post I did and also my JSP form.
If you see something wrong, please tell me.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing I see wrong is that your form action does not include the context path.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic