473,413 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

How to encode a URL in jsp?

108 100+
I want to encode a url and send it to another page.However, when I press the link, it gives me page not found..

<%
String url="newjsp.jsp?name=vimal&id=0812573&NIC=vimal basdeo&f=nasha sahdjsa hk";

url=URLEncoder.encode(url,"UTF-8");
out.println("<a href="+url+"><img src='ajith-billa2.jpg' alt='Ajit'></a>");


%>



My URL becomes http://localhost:8080/WebApplication1/newjsp.jsp%3Fname%3Dvimal%26id%3D0812573%26NIC%3Dv imal+basdeo%26f%3Dnasha+sahdjsa+hk after being encoded


How do I sort this prob out?
Feb 20 '11 #1

✓ answered by Abhishek Saha

If I'm understanding correctly, this is not a URL encoding problem.

Problem might be the file location.

When we do url encoding basically we apply these rules.
  • The alphanumeric characters "a" through "z", "A" through "Z" and "0" through "9" remain the same.
The special characters ".", "-", "*", and "_" remain the same.[/list]
  • The space character " " is converted into a plus sign "+".
  • All other characters are unsafe and are first converted into one or more bytes using some encoding scheme. Then each byte is represented by the 3-character string "%xy", where xy is the two-digit hexadecimal representation of the byte. The recommended encoding scheme to use is UTF-8. However, for compatibility reasons, if an encoding is not specified, then the default encoding of the platform is used.
    For example using UTF-8 as the encoding scheme the string "The string ü@foo-bar" would get converted to "The+string+%C3%BC%40foo-bar" because in UTF-8 the character ü is encoded as two bytes C3 (hex) and BC (hex), and the character @ is encoded as one byte 40 (hex).

So i think you are encoding the url correctly.

is your corrent file( i mean where this jsp code is being running, and the newjsp.jsp are in same folder?

Do a dry run.

Expand|Select|Wrap|Line Numbers
  1. <%
  2. /* For the time being let these statements be commented
  3. String url="newjsp.jsp?name=vimal&id=0812573&NIC=vimal basdeo&f=nasha sahdjsa hk";
  4.  
  5. url=URLEncoder.encode(url,"UTF-8");
  6. */
  7. out.println("<a href="http://localhost:8080/WebApplication1/newjsp.jsp?name=vimal&id=0812573&NIC=vimal basdeo&f=nasha sahdjsa hk"><img src='ajith-billa2.jpg' alt='Ajit'></a>");
  8.  
  9. %>
  10.  
And check whether its working or not.

1 22988
If I'm understanding correctly, this is not a URL encoding problem.

Problem might be the file location.

When we do url encoding basically we apply these rules.
  • The alphanumeric characters "a" through "z", "A" through "Z" and "0" through "9" remain the same.
The special characters ".", "-", "*", and "_" remain the same.[/list]
  • The space character " " is converted into a plus sign "+".
  • All other characters are unsafe and are first converted into one or more bytes using some encoding scheme. Then each byte is represented by the 3-character string "%xy", where xy is the two-digit hexadecimal representation of the byte. The recommended encoding scheme to use is UTF-8. However, for compatibility reasons, if an encoding is not specified, then the default encoding of the platform is used.
    For example using UTF-8 as the encoding scheme the string "The string ü@foo-bar" would get converted to "The+string+%C3%BC%40foo-bar" because in UTF-8 the character ü is encoded as two bytes C3 (hex) and BC (hex), and the character @ is encoded as one byte 40 (hex).

So i think you are encoding the url correctly.

is your corrent file( i mean where this jsp code is being running, and the newjsp.jsp are in same folder?

Do a dry run.

Expand|Select|Wrap|Line Numbers
  1. <%
  2. /* For the time being let these statements be commented
  3. String url="newjsp.jsp?name=vimal&id=0812573&NIC=vimal basdeo&f=nasha sahdjsa hk";
  4.  
  5. url=URLEncoder.encode(url,"UTF-8");
  6. */
  7. out.println("<a href="http://localhost:8080/WebApplication1/newjsp.jsp?name=vimal&id=0812573&NIC=vimal basdeo&f=nasha sahdjsa hk"><img src='ajith-billa2.jpg' alt='Ajit'></a>");
  8.  
  9. %>
  10.  
And check whether its working or not.
Feb 21 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: francescomoi | last post by:
Hi. I'm trying to store a text within a MySQL field (v 3.23.58) by using MySQLdb (v 1.2.1c3). The text is: "telephone..." (note the last character) And I get this error message:...
5
by: Scott Matthews | last post by:
I've recently come upon an odd Javascript (and/or browser) behavior, and after hunting around the Web I still can't seem to find an answer. Specifically, I have noticed that the Javascript...
4
by: Newbie | last post by:
How would I modify this form to encode *all* the characters in the 'source' textarea to the '%xx' format & place result code into the 'output' textarea? (cross browser compatable) Any help is...
3
by: Peter | last post by:
Hi, I try to make up a javascript string which contains numeric numbers in any positions. For example, I want to make a string: secretcode, where secretcode.charAt(0)==(-21),...
1
by: AR | last post by:
I would like to know more about the Encode/Decode feature available within MS Access. This is what I have read from Microsoft Office OnLine: "The simplest method of protection is to encode the...
4
by: Darrel | last post by:
How does HTML.encode work? I'm trying to save text in a hidden form field into a SQL DB. The tedt is HTML (from a WYSIWYG editor...X-standard). One problem I have is that stray apostrophe's in...
7
by: jtfaulk | last post by:
I need to encode some information on the server side using ASP.NET with C#; sending via HTTP to a client side application, that needs to be decoded in an MFC C++ application. I'm not sure if I...
6
by: 7stud | last post by:
s1 = "hello" s2 = s1.encode("utf-8") s1 = "an accented 'e': \xc3\xa9" s2 = s1.encode("utf-8") The last line produces the error: --- Traceback (most recent call last):
4
by: J Peyret | last post by:
Well, as usual I am confused by unicode encoding errors. I have a string with problematic characters in it which I'd like to put into a postgresql table. That results in a postgresql error so I...
1
by: anonymous | last post by:
1 Objective to write little programs to help me learn German. See code after numbered comments. //Thanks in advance for any direction or suggestions. tk 2 Want keyboard answer input, for...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.