File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes How to add Query String values to different links in HTML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to add Query String values to different links in HTML" Watch "How to add Query String values to different links in HTML" New topic
Author

How to add Query String values to different links in HTML

Stan Zh
Greenhorn

Joined: Aug 05, 2009
Posts: 4

These two questions may be basic but I am not familiar with java and they are problem for me. I appreciate you help. I am trying to extract values from the Query String (using java below) and add different values to different links in my HTML code. The script that generates the Query String is obviously inconsistent and sometimes is using “&” as delimiter and sometimes “&”...

[code] http://powerpoint-to-flash.sminteriors.net/download-powerpoint-to-flash.shtml?userdir=dc2939cbab8315998ece18d0ad0d266c&action=download&path=/users/dc2939cbab8315998ece18d0ad0d266c/&file=ppt2flash2.20090802-1421.swf [code]

Therefore, I need to resolve two things:

1) How to tell my little java applet to use either “&” OR “&” when splitting values?
--------------------------------------------------
[code] <script type="text/javascript">
<!--
function querySt(ji) {
hu = window.location.search.substring(1);
gy = hu.split("&");
for (i=0;i<gy.length;i++) {
ft = gy[i].split("=");
if (ft[0] == ji) {
return ft[1];
}
}
}
var ud = querySt("userdir");
var act = querySt("action");
var pt = querySt("path");
var fl = querySt("file");

-->
</script> [code]

2) How to incorporate those values in different links in my HTML for example (I know it doesn’t work):
[code] a href="/cgi-bin/script.cgi?document.write(act)" title="something">your ZIP file <javascript:document.write(fl);> (<!--#fsize file="uploads/document.write(pt+fl);"-->) [code]

Thank you for your time,
Stan
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

Stan Zh, please check your private messages for an important administrative matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

That's not Java, that's JavaScript. They have no relationship.

Moved to the HTML/JavaSript forum.

Also, please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

OK, you've shown us some code that isn't making much sense. How about you describe what you are trying to do, rather than how you are trying to do it.
Stan Zh
Greenhorn

Joined: Aug 05, 2009
Posts: 4
Bear Bibeault wrote:OK, you've shown us some code that isn't making much sense. How about you describe what you are trying to do, rather than how you are trying to do it.


Thank you for your quick response. I thought I described what I am trying to do in my 3rd sentence starting from the very beginning... I could clarify if it is not clear... I am trying to extract values from a Quesry String (included in the posting) which works 50% because thescript that generates the Quesry string obviously for some reason (may be typo or whatever) is using "&" and "&amp;" to separate values. So instead of asking author of that script to correct is which may take too much time i decided it might be easier to find out how to tell the javascript to use both or either "&" and "amp;" to split those values from the Query String.

Once I get those values I need to incorporate different values in different links in my HTML code but I have never done it before and I do not know how to do that...

These are the two problems I need to resolve.

Thanks
Stan
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

Did you read my private message as instructed?
Stan Zh
Greenhorn

Joined: Aug 05, 2009
Posts: 4
Bear Bibeault wrote:OK, you've shown us some code that isn't making much sense. How about you describe what you are trying to do, rather than how you are trying to do it.


I see now reading forum post one can not see that delimiters are different and not consistent in the Query String... May be if one click the link will see in the browser path the difference - it is "&" and &---a-m-p-: (the difference is displayed on the forum post preview but not in the actual post
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

OK, I can see you're not very familiar with HTML entities so I went into you post and fixed it up so that your &amp; text doesn't change to just &. That makes things easier to understand.

For the &amp; issues, band-aiding them in your code is clearly the wrong way to approach the problem. Getting them fixed at the source is the real issue.

But in the meantime, why not just do a simple string substitution of &amp; with &?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

Read and respond to my private message before posting again. Otherwise, you may find your account removed.
Stan Zh
Greenhorn

Joined: Aug 05, 2009
Posts: 4
Bear Bibeault wrote:OK, I can see you're not very familiar with HTML entities so I went into you post and fixed it up so that your &amp; text doesn't change to just &. That makes things easier to understand.

For the &amp; issues, band-aiding them in your code is clearly the wrong way to approach the problem. Getting them fixed at the source is the real issue.

But in the meantime, why not just do a simple string substitution of &amp; with &?


Because when I substitute it - I get only values that are preceded with &amp; and the rest are ignored and marked as undefined
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to add Query String values to different links in HTML