Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to pass "&" sign from .jsp to servlet?

Posted on 2004-04-20
7
Medium Priority
?
301 Views
Last Modified: 2010-04-01
I have a jsp page which will pass a request to Serlvet like this:
for example:
this option is "Q&A", and the link wil be "http://xxx.com/run?category=Q%20&%20A"

But when I run
-----------------------------------------------------------
category = request.getParameter("cateogry");
System.out.println(category);
-----------------------------------------------------------
The result is only "Q", ...... which means "&A" is gone.

Can anyone help me on this?
0
Comment
Question by:tsongwei
7 Comments
 
LVL 9

Expert Comment

by:Nick_72
ID: 10869398
try %26


"http://xxx.com/run?category=Q%20%26%20A"
0
 

Author Comment

by:tsongwei
ID: 10869451
I am sorry I ask the question wrong.
My question should be suppose I have a loop which will create links for cateogries.
for example:
category ....  link
--------------------------
home ........ http://xxx.com/run?cateogry=home
fun ............ http://xxx.com/run?catrgory=fun
Q&A .......... http://xxx.com/run?category=Q&A   <---- this one is wrong
--------------------------
how do I fix this? to make it pass "Q&A" instead of just "Q"

Thank you.
0
 
LVL 9

Accepted Solution

by:
Nick_72 earned 300 total points
ID: 10869500
I would still replace the '&' with %26.

If you show me more code maybe I can provide better help, but generally:

String link = " http://xxx.com/run?category=Q&A".replaceAll("&", "%26");
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Assisted Solution

by:searlas
searlas earned 200 total points
ID: 10869522
More generally, use URLEncoder:
<%@ page language="java" import="java.net.URLEncoder" %>
<%
String cat = "q&a"; // or whatever
%>
<a href="http://xxx.com/run?category=<%= URLEncoder.encode(cat) %>">link text</a>
0
 

Author Comment

by:tsongwei
ID: 10869587
I got it!!!
Thank you so much. Solved my problem in 20 minutes with this forum.

Thank you again.
0
 
LVL 9

Expert Comment

by:Nick_72
ID: 10869609
Glad to help :)
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10869836
Try what nick says without the %20 wich are spaces just

"http://xxx.com/run?category=Q%26A"

Javier
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Steps to fix error: “Couldn’t mount the database that you specified. Specified database: HU-DB; Error code: An Active Manager operation fail”
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question