JSP link to controller mapping that returns mapping to jsp file but browser has nothing to show

Viewed 161

I have a link

<a href="<c:url value="localhost:8080/CustomerRelationshipManagement/configureUpdate?
                            firstName=${temp.firstName}&lastName=${temp.lastName}&email=${temp.email}"/>">Update</a>

that directs to a spring mvc mapping

@RequestMapping(value="configureUpdate", method = RequestMethod.GET)
public String configureUpdate(@RequestParam("firstName") String firstName, 
        @RequestParam("lastName") String lastName,  @RequestParam("email") String email, 
        Model model)
{

    Customer customer = new Customer(firstName, lastName, email);

    model.addAttribute("customer", customer);

    return "update-customer";
}

and, as a result, the browser in eclipse just displays

The webpage cannot be displayed

I have tried to remedy this but haven't discovered any means for the browser to continue to the next JSP page after the processing is done.

1 Answers

The webpage cannot be displayed

This is a typical Internet Explorer error message which will be shown when the browser couldn't reach the target in first place. For example, because of a corrupted URL syntax.

If you have inspected the generated HTML output of your JSP page, you would have noticed that it has produced the below HTML code:

<a href="localhost:8080/CustomerRelationshipManagement/configureUpdate?
                        firstName=&lastName=&email=">Update</a>

It doesn't start with a scheme or an /, so it becomes relative to the current URL. Imagine that the current URL is http://localhost:8080/CustomerRelationshipManagement/some.jsp, then the target URL will become http://localhost:8080/CustomerRelationshipManagement/localhost:8080/CustomerRelationshipManagement/configureUpdate?firstName=&lastName=&email=

This is certainly not valid. The target URL should have become http://localhost:8080/CustomerRelationshipManagement/configureUpdate?firstName=&lastName=&email=.

In other words, the generated HTML output should have looked like:

<a href="http://localhost:8080/CustomerRelationshipManagement/configureUpdate?
                        firstName=&lastName=&email=">Update</a>

Or domain-relative:

<a href="/CustomerRelationshipManagement/configureUpdate?
                        firstName=&lastName=&email=">Update</a>

Or if the current page is currently sitting in /CustomerRelationshipManagement folder:

<a href="configureUpdate?firstName=&lastName=&email=">Update</a>

You need to adjust your JSP code accordingly that it produces exactly the desired HTML code. If the JSP page is served by the very same web application as the target URL, and you want to keep using the <c:url> tag, then it should look like this:

<c:url var="configureUpdateURL" value="/configureUpdate">
    <c:param name="firstName" value="${temp.firstName}" />
    <c:param name="lastName" value="${temp.lastName}" />
    <c:param name="email" value="${temp.email}" />
</c:url>

<a href="${configureUpdateURL}">Update</a>

It will generate a domain-relative URL.

Related