File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URL has # included; want to send the url including # to the server

 
Tilak Gorantala
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 1
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Arun Giridhar
Ranch Hand
Posts: 181
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Naveen Kumar Kumar
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • 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

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic