0

i am working on a project. my work is retrieve data from database and displaying them. if required sent to next page for further processing. my problem is i got value from database and i want to send it another jsp or servlet using href. value i am retrieving is :

        <%=special.getString("id")%>

send it to:

      <a href="new.jsp?id=<%=special.getString("id")%>" class="action_button">Buy Now</a>

but when send data like this error is

error message is

is that correct? how do i do it? what is the correct method. i am struck here for long time please help me.

5 Answers5

1

Use single quotes around id instead double.

"new.jsp?id=<%=special.getString('id')%>"
Cortwave
  • 4,747
  • 2
  • 25
  • 42
0

Use single quote inside double quote. I am trying to type code but not able to type. now it should work

0

You need to escape your quotes first or use single quotes so that your double quotes can work:

Note: Untested.

<a href='new.jsp?id=<%=special.getString("id")%>' class="action_button">Buy Now</a>
Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
0

I see in your error message it says DOUBLE_WHITESPACE in QUERY. I would suggest you try encoding you url.

  <% String id=java.net.URLEncoder.encode(special.getString("id") , "UTF-8");%>
  <a href='new.jsp?id=<%=id%>' class="action_button">Buy Now</a>
Sas
  • 2,473
  • 6
  • 30
  • 47
0

If you're serious about JSP development ditch scriptlets (which went out of common use 10+ years ago) and familiarize yourself with the Java Standard Tag Libraries and JSP Expression Language.

I am not quite sure what 'special' is here, however using EL your code will look something like the below:

<!-- special is an object with a method getId()-->
<a href="new.jsp?id=${special.id}" class="action_button">Buy Now</a>

or

<!-- special is an object with a method getString(String key) -->
<a href="new.jsp?id=${special.getString('id')}" class="action_button">Buy Now</a>

If this doesn't work then there is no bean with key 'special' in any scope.

Note that if you are working with a database in your JSP you should consider refactoring to use the standard JSTL SQL tags. See below for an example:

http://www.tutorialspoint.com/jsp/jstl_sql_query_tag.htm

See also:

http://www.tutorialspoint.com/jsp/jsp_standard_tag_library.htm

http://beginnersbook.com/2013/11/jsp-expression-language-el/

*Note for the second example to work your app need to be compliant with the Servlet 3 specification (as passing mthod params was nut supported in EL before this). See further: https://stackoverflow.com/a/6337222/1356423

Community
  • 1
  • 1
Alan Hay
  • 22,665
  • 4
  • 56
  • 110
  • special is ResultSet. sorry if my question is not clear. which are retrieved from database and i m displaying then like this <% While(special.next()){ %>
    • <%= special.getString("company")%>
    • <%= special.getString("catagory")%>
    <% } %>
    – user3552285 Feb 12 '15 at 07:16
  • when i click on 'more details' it should go to new.jsp where it can display more detials about that particular company. for that i need to send 'id' of that particular row to see more details of that particular row. how do i sent id of that particular row to new jsp where i can retrieve full details and display it in new.jsp page?? or am i doing it wrong? my main problem is when i click on 'more details' all details of that row should go to next page i.e. new.jsp. how do i do it??? – user3552285 Feb 12 '15 at 07:19
  • As I said previously scriptlets are hideous, ancient technology you should not be using, see here for db example with JSTL and EL. http://www.tutorialspoint.com/jsp/jstl_sql_query_tag.htm – Alan Hay Feb 12 '15 at 07:58
  • thanks for the help. i know i am using wrong code. i just want solution. thanks you very much – user3552285 Feb 12 '15 at 08:53