0

I want to send a value in URL that value contains more than one words i am using the given concept for example

<a href=page.jsp?variable1=value1&variable2=value2>click here</a>

Suppose in above value value1=aa and value2=bb cc dd but in the url of page.jsp i am getting value1=aa and value2=bb only and the rest value "cc dd" is missing.

what should i do to get complete value for example value2=bb cc dd

I am giving here my code after making it more simple to focus on desire problem

`<%
        MongoClient mongo = new MongoClient("localhost",27017);
        DB database = mongo.getDB("studentDB");
        DBCollection collection = database.getCollection("AskQuestion");
        DBCursor cursor = collection.find();
        String bodycontent="";

        while(cursor.hasNext())
        {       
            DBObject str=cursor.next();             
            bodycontent+="<table><tr><td><div><a href=Answer.jsp?ObjectID="+str.get("_id")+"&Title="+ str.get("TITLE") +"> "+ str.get("TITLE") +"</a></div></td></tr></table>";
        }
        out.print(bodycontent);
        %>`

For example str.get("_id") gives value "55093da9223da86a0212b364" and str.get("TITLE") gives value "Question Title" . Now my problem is i got value in Answer.jsp for str.get("TITLE") is only "Question" but not "Title" and i want the full value i.e Question Title. I hope i am clear with my problem.

Sumit Saw
  • 1
  • 2

1 Answers1

0

Try encoding your second variable and then attach it.

example: bb%20cc%20dd

<a href=page.jsp?variable1=value1&variable2=bb%20cc%20dd>click here</a>

You need to use java script for encoding your URL see this question for more details.

Passing a URL as a GET parameter in Javascript

Edit

See these answers

How to URL encode a URL in JSP?

http://www.coderanch.com/t/521213/JSP/java/encoding-URL-href-element-JSP

Community
  • 1
  • 1
smali
  • 4,687
  • 7
  • 38
  • 60
  • Yes its working in this case but what should i use if the value bb cc dd is coming from database and i have to check this string for equality in another page with another string – Sumit Saw Apr 20 '15 at 10:17