• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

URL not redirecting properly

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an application which runs on the client server but I have to deploy it locally on tomcat server. I was able to do that. But with an exception. Every page that has a form has action /ABC which is a servlet that directs the request.
The problem is when I login the URL becomes something like localhost:8080/ABC and the page goes blank.
But in firebug it shows the right URL where the page should be directed under header ----> location.
It also says 302 Moved Temporarily. Any clue as to how can I direct it to the right URL.
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Neha,

What is the servlet doing which is mapped through the url-pattern Comptix? You said it's directing to another URL. Make sure the URL to which the request is being redirected is in the proper location and is working.
 
Neha Suneja
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I just put the URL that is in the location(the right URL) in the address bar. It works fine. I can run the whole application by copying and pasting the URL in header(location). But I want to overcome that
 
Ranch Hand
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please post the code?
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in action attribute of your form tag, only write "Comptix" instead of "/Comptix".
in tomcat " / " refers to the root so localhost:8080/Comptix url will find application with name "Comptix" instead of particular servlet.

try this.

Prashant
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

prashant chindhade wrote:in action attribute of your form tag, only write "Comptix" instead of "/Comptix".
in tomcat " / " refers to the root so localhost:8080/Comptix url will find application with name "Comptix" instead of particular servlet.

try this.


No. Don't try that. This is bad advice.

The action URL should always be a server-relative URL starting with the context path.

For example:
 
Neha Suneja
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have my application in the ROOT folder only, the application code is fine. Its directing to a right page as shown in the location. I cannot paste the code here because the its huge. There is some issue that lies in "302 moved temporarily". Any solutions on that?
 
Sumit Patil
Ranch Hand
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"302 Moved Temporarily" is a response sent from tomcat to the browser so that the browser can send a new request to the given URL which you mention in the sendRedirect method.
 
Neha Suneja
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just changed localhost:8080 to http://localhost:8080 in a properties file and it started working.
 
Prashant Chindhade
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear Bibeault sir,

can you explain me why this is bad advice ?
i really want to know because i am using this only.
how can we redirect in other way?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because without the leading context path, the URL is relative to the URL of the current page. If the mapping gets changed, everything starts to break. This is know as "fragile" code and should be avoided.

By starting all URLs with the context path, they will always work no matter if files are moved around, or if servlet mappings are changed.
 
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The action URL should always be a server-relative URL starting with the context path.

For example:
view plaincopy to clipboardprint?
action="${pageContext.request.contextPath}/servlet-path"



I am very much confused.

If i go for simple mapping as in <servlet> and <servlet class> and use the <url-pattern> as the action, appended to "./", will there be any problem?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, see my previous reply. Even if you get it to work now, a page-relative URL is subject to fragility which is something to be avoided. Server-relative URLs keep working even if the URL of the containing page changes.
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear

suppose previously i used to invoke a servlet with url-pattern as "/commit", now onwards its better to use . Correct me if i am wrong.

But how will it know that it has to invoke servlet with url-pattern with "/commit"?>
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Think! If the servlet path is "/commit", then that's what you use for the servlet path.


 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh yes. That was senseless Question by me.

Thanks for your reply Bear.
I learnt a wonderful thing
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Ranch Hand
Posts: 87
jQuery
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear Bibeault Sir,

I have a doubt , what is <html:base >.

If i am using base path in my jsp, i will not get any path related errors. I mean i was accessing any resource relative to my context path.





 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I assume that's a Struts tag that turns into HTML <base> markup. Yes, that can work, but I'm not a fan of doing things that way, especially without the server-side tags because it's hard to use <base> correctly and to keep the page portable.

I also prefer to keep the URLs explicit rather than base-relative.
 
S Subbu
Ranch Hand
Posts: 87
jQuery
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you sir, now onwards i follows you
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic