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
Solved

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

Posted on 2004-04-20
7
288 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can I clean log of  running tomcat 7 server ? 3 127
servlet concurrency 13 110
I get error: useBean: Duplicate bean name: {0} 1 148
How  can  i  resolve  HTTP Status 404 -? 8 42
If you are looking at this article, you have most likely been hit by some version of ransomware and are trying to find out if there is anything you can do, or what way you should react - READ ON!
There's a lot of hype surrounding blockchain technology. Here's how it works and some of the novel ways it' s now being used - including for data protection.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 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