0

i have a problem with spring url tag in my jsp page. Here is my index.jsp page:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<spring:url var="registrationUrl" value="/register"/>

<!DOCTYPE html>
<html>
<body>
<h2>Index page</h2>
    <a href="${registrationUrl}">Register</a>
</body>
</html>

after clicking on "Register" link my URL format looks like this: http://localhost:8080/$%7BregistrationUrl%7D

instead of: http://localhost:8080/register

so the question: what i am missing?

4 Answers4

2

@Dmitriy Tatarenko's answer works for me too.. one change here is to carefully make the replacement as follows:

From something like:

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Application Name</display-name>
</web-app>

to:

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">

  <display-name>Application Name</display-name>
</web-app>

Note: Do not chop off the <!DOCTYPE...> line as the packaging may not work.

1

I found the solution. I didn't expect but the problem was in my web.xml. It used old xml schema:

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

so i replice this to newest schema:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">

Thanks all to try help me. P.S. Sorry for my bad engilsh.

0
<spring:url value="/something" var="url" htmlEscape="true"/>
 <a href="${url}">...</a>

 <c:url value="/something" var="url"/>
 <a href="<c:out value='${url}'/>">...</a>

The one important difference between c:url and spring:url is, that c:url does not html encode the created url. But for a valid url the & between the url parameters must be a &. So you need the c:out to escape it. -- In spring:url you have this functionality already included (if I understand the documentation correct).

0

You may try to add htmlEscape="true" to your spring:url tag. Should be for your particular case :

<spring:url var="registrationUrl" value="/register"  htmlEscape="true"/>

May be duplicate of another stackoverflow thread. See : How to use <spring:url /> with an <a> tag?

Sam

Community
  • 1
  • 1
Sam
  • 1
  • 1