• 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 has # included; want to send the url including # to the server

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

let suppose there are 2 applications say A & B.

I have my Servlet code in application A and I need to send a url to application B, which validates my credentials and returns me to the url which I gave firstly(single sign on authentication is happening here).

Now, when i am giving url which includes # in it. (let suppose for ex: http://google.com/DOC-68650#test_anchor ). and when I am giving this url, the total url has to go to application B, but only http://google.com/DOC-68650 is going to application B. I want to include #test_anchor also while passing a url from A application to B appliaction.

Can anyone please tell me how to achieve this. Appreciate your help on this.

Thankyou,
Gopi.
 
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
You'll have to rethink this. The hash anchor is a client-side concept and is not passed to the server as part of the request.

Inspecting the raw text of the request reveals that the hash anchor is not included.
 
Tilak Gorantala
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear,

But if I encode the url and then send it to server. If suppose I write encode & decode statements like below,

try {

String url = servletRequest.getRequestURL();

String encodedUrl = URLEncoder.encode(url, "UTF-8");

log.debug("Encoded URL " + encodedUrl);

String decodedUrl = URLDecoder.decode(url, "UTF-8");

log.debug("Dncoded URL " + decodedUrl);

} catch (UnsupportedEncodingException e) {

System.err.println(e);

}

I tried above code and i'm getting an error as -

[javac] found : java.lang.StringBuffer
[javac] required: java.lang.String
[javac] String url = servletRequest.getRequestURL();
[javac] ^
[javac] 1 error

 
Tilak Gorantala
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear,

I have put the encode and decode statements and I could compile them and I have even built the JAR file successfully.

try {
//String url = (servletRequest.getRequestURL()).toString();

log.debug("Given URL " + servletRequest.getRequestURL());

String encodedUrl = URLEncoder.encode((servletRequest.getRequestURL()).toString(),"UTF-8");

log.debug("Encoded URL " + encodedUrl);

String decodedUrl = URLDecoder.decode((servletRequest.getRequestURL()).toString(),"UTF-8");

log.debug("decoded URL " + decodedUrl);

//final HttpServletRequest servletRequest = (ServletRequest) decodedUrl;

}
catch (UnsupportedEncodingException e) {

System.err.println(e);

}

I am using doFilter method in my program, I think it is a safe way to encode. Is it?
 
Tilak Gorantala
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to check a url whether it is valid or not, Please include # symbol while validating the url using Java
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The fact that you're battling the Servlet API should be an indicator that you're going about whatever problem you're trying to solve the wrong way.

The proper approach is to take a step back and ask yourself *why* you want to do this. To me it sounds as if URL parameters might work as well, and would not make you jump through hoops to get it done.
 
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

Ulf Dittmer wrote:The fact that you're battling the Servlet API ...



Not only the Servlet API, but HTTP itself.

Start over. This is not the approach you seek.
 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using Referer just like the Coderanch is done (they make it hidden in Login page). By using referer they pull back to same page after Login. For # included , you got to deal with javascript >> onsubmit then >>encodeURIComponent(). Is this correct ranchers ?
 
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
It could likely be kludged with some JavaScript, but the point we're making is that kludges should not be necessary. The OP should rethink (and post) what he is actually trying to accomplish.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gopi Gorantala wrote:How to check a url whether it is valid or not, Please include # symbol while validating the url using Java



Gopi, not sure if you are still searching for validating the url, however one of the existing Apache class: "UrlValidator" can be of some help for you to start validating the urls...check the below link:

http://commons.apache.org/validator/apidocs/org/apache/commons/validator/routines/UrlValidator.html

reply
    Bookmark Topic Watch Topic
  • New Topic