Solved

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

Posted on 2004-04-20
7
283 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
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 75 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 7

Assisted Solution

by:searlas
searlas earned 50 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
A safe way to clean winsxs folder from your windows server 2008 R2 editions
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now