• 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

Got a very strange JS problem here

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys.

I've got a JavaScript setTimeout function on my admin.jsp page which when a user posts a news post it will refresh the page by sending them to the newspost page via admin.jsp?page=newspost. The code is below:



The news post form has got a GET var attached to the action EG action=admin.jsp?page=newspost&refresh=true

When I type some news and press Post the timeout will kick in but it will redirect to the index.jsp page and not the admin.jsp?page=newspost page as where it's meant to go. Why on gods earth is it not sending me to where ive specified the redirect to go in the JavaScript code??? Help much appreciated and many thanks!
 
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
In a JSP you should be using a server-relative URL that begins with the contact path. That eliminates all first of page-relative URL issues.
 
Michael Portman
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:In a JSP you should be using a server-relative URL that begins with the contact path. That eliminates all first of page-relative URL issues.



My JSP's only contain JSTL EL tags. All my actual Java code are kept away in class files. My index page is actually a servlet which forwards certain attributes to my index.jsp page, then EL's in my JSP's take care of the forwarded request attributes. How could a JavaScript redirect affect this?
 
Michael Portman
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just forget about it being a java webapp, why is the javascript code redirecting me to my index page when ive statically put in the URL???
 
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

Michael Portman wrote:How could a JavaScript redirect affect this?


How the redirect is affected is irrelevant. It's the URL that matters.

It's easy to use the EL to grab the context path to format a seder-relative URL. Because of the way Java web apps work, page-relative URLs are fragile and error-prone.

It's not possible to "forget" that the web app is Java-based -- it's fundamental to the web app, in the same way that a webpack-based JS app has its own patterns for how to use URLs.
 
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

Michael Portman wrote:Just forget about it being a java webapp, why is the javascript code redirecting me to my index page when ive statically put in the URL???


You haven't. The URL you are using is page-relative and resolved against the current URL. It's a bad way to code regardless of the type of web app as how it resolved is dependent on outside factors -- in this case, the current URL. In a Java web app, server-relative URLs are the best way to avoid issues.
 
Michael Portman
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

Michael Portman wrote:Just forget about it being a java webapp, why is the javascript code redirecting me to my index page when ive statically put in the URL???


You haven't. The URL you are using is page-relative and resolved against the current URL. It's a bad way to code regardless of the type of web app as how it resolved is dependent on outside factors -- in this case, the current URL. In a Java web app, server-relative URLs are the best way to avoid issues.



It doesnt matter now anyway cos im re-coding the site.
 
Arch enemy? I mean, I don't like you, but I don't think you qualify as "arch enemy". Here, try this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic