Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-04-20
7
Medium Priority
?
298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
Experts give $3,000 toward hurricane relief efforts—but that's not all!
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

670 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