Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Unable to read '#' value using getParameter

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Thanked 0 Times in 0 Posts

    Default Unable to read '#' value using getParameter

    I have written a Java Servlet which queries the database and returns the result to JSP. I am executing the SQL Statement based on the parameters passed from the URL

    //Reading Parameter
    String User = request.getParameter("userid");

    //Executing the SQL
    String sqluser = "SELECT 1 FROM <table name> WHERE username = ?
    pstmt = con.prepareStatement(sqluser);
    pstmt.setString(1, User); //Setting the value passed from URL
    rset = pstmt.executeQuery();

    The sample URL: http:\testenv.com\test?userid=tana
    The above URL displays correct result since user='tana'.

    But there are some users that have "#" in their user name.

    For e.g: http:\testenv.com\test?userid=la#na

    The SQL Statement does not return any value because User= 'la' in above case even though the URL has "la#na". Can i get the value "la#na" using getParameter? If so what do i need to do?

  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Tavistock, UK
    Thanked 103 Times in 93 Posts

    Default Re: Unable to read '#' value using getParameter

    That '#' is the Fragment Identifier:

    Fragment identifier - Wikipedia, the free encyclopedia

    You won't see it at the server because most user agents (browsers) don't send it to the originating server - it's used for identifying locations *within* the resource. If you're using '#' as a valid character in fields in your application, then you must encode the # characters before you build them into request URLs. Both javascript and Java have functions for 'URL encoding' # characters.

Similar Threads

  1. Read input, read file, find match, and output... URGENT HELP!
    By MooseHead in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 3rd, 2012, 11:01 AM
  2. Web browser unable to read javascript etc.
    By Maloto970 in forum Java Networking
    Replies: 1
    Last Post: February 21st, 2012, 09:11 AM
  3. [SOLVED] I am unable to read radio button actions in JSP
    By abhiM in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 17th, 2011, 01:41 AM
  4. [SOLVED] Read double from console without having to read a string and converting it to double.
    By Lord Voldemort in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: June 26th, 2011, 08:08 AM
  5. Replies: 4
    Last Post: August 13th, 2009, 05:54 AM

Tags for this Thread