Search code examples
javajsphrefnetbeans-7servlets

In tag <td><a href="....."></a></td> DOUBLE_WHITESPCE in query href


I have a very strange problem.

    <table border ="1">
                        <tbody>
                            <c:forEach var="question" items="${questions}">                                
                                <tr>
                                    <td>
                                        ${question.getQuestion()}                                     
                                    </td>
                                    <td> 
                                        <c:forEach var="answer" items="${question.getAnswers()}">                                                      
                                            <input type="checkbox" name ="user_answer" value="${answer.getAnswer()}">
                                            ${answer.getAnswer()}
                                            <br />
                                        </c:forEach>                                   
                                    </td>
                                    <td>
                                    <a href="/TutorWebApp/controller?command=edit_qestion&amp;question=${question}">
                                           Edit 
                                    </a>
                                    </td>
                                </tr>
                            </c:forEach>                  
                        </tbody>
</table>

But If I use in I get next error error_image

But if I don't use tag <a> in <td> it's OK. I don't have any ideas. Thanks


Solution

  • You need to encode your question text (or whole URL) here by calling URLEncoder#encode()

    You can look at this Q&A on how to encode a URL in JSTL.

    Alternatively you can try calling JSTL's escapeXml function on your question text.