Solved

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

Posted on 2004-04-20
7
285 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
console vs log file 16 79
difference between projection and projection list in hibernate 1 108
withoutString  challenge 40 197
JavaScript parse form with colon separated values 2 77
Troubleshooting common task sequence error codes
Read about the ways of improving workplace communication.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

15 Experts available now in Live!

Get 1:1 Help Now