Problems with spring mvc friendly url

Asked

Viewed 176 times

1

by including a last page in my project I got a url problem, from which, I could not identify the problem.

JSF scenario:

  • Certification module: href="customer service/"
  • Customer details: href="client/${nrPasta}"
  • Certification module: href="customer service/"

Access the service module, this will list all registered customers. I select one of the customers and access the details of the same, which brings me the url "app/customer/customer/123", until this point works normally, however, if the user decides to click again on the link of the module the url loaded will be "app/customer/customer/customer/customer/customer/customer".

@RequestMapping("/atendimento")
public class Atendimento {

  @RequestMapping("/cliente")
  public String atendimentoCliente(){};

  @RequestMapping("/{nrPasta}")
  public String atendimentoDetalhes(){}

URL base: localhost:8084/app/

So hang on, have any idea what might be going on, because I’m not identifying my mistake.

Attendance.jsf

<tbody>
<c:forEach items="${cliente}" var="cl">
 <tr>
  <td>${cl.nrPasta}</td>
  <td>${cl.nome}</td>
  <td class="hidden-480">
    <span class="label label-sm label-success">Novo</span>
  </td>
  <td>
   <div class="hidden-sm hidden-xs action-buttons">
    <a class="blue" href="cliente/${cl.nrPasta}">
     <i class="ace-icon fa fa-search-plus bigger-130"></i>
    </a>
   </div>
  <div class="hidden-md hidden-lg">
   <div class="inline pos-rel">
    <button class="btn btn-minier btn-yellow dropdown-toggle" data-toggle="dropdown" data-position="auto">
     <i class="ace-icon fa fa-caret-down icon-only bigger-120"></i>
    </button>
    <ul class="dropdown-menu dropdown-only-icon dropdown-yellow dropdown-menu-right dropdown-caret dropdown-close">
     <li>
      <a href="cliente/${cl.nrPasta}" class="tooltip-info" data-rel="tooltip" title="View">
      <span class="blue">
       <i class="ace-icon fa fa-search-plus bigger-120"></i>
      </span>
     </a>
    </li>
   </ul>
  </div>
 </div>
</td>
</tr>
</c:forEach>
</tbody><!-- tbody -->

Module with link Service:

<ul class="submenu">
  <li class="">
    <a href="atendimento/cliente">
     <i class="menu-icon fa fa-caret-right"></i>
      Atendimento
    </a>
    <b class="arrow"></b>
  </li>
 </ul>
  • Place the code of the page that has the button to navigate to the module link in the customer details.

1 answer

0

It is not considered good practice to put the context of the web application or the full address hardcoded on the page. If you change anything, then you will have to search throughout the project.

Are you using the href with the relative path, then atendimento/cliente will be included at the end of any path where this link appears.

To directly reference the directory atendimento, at the root of your application, use

<a href="/atendimento/cliente">

Edited

Whereas the context of the application is removed when you use the absolute path and you are creating a JSF page, try using the tag <h:link>

<h:link value="Texto" outcome="/atendimento/cliente" />

Don’t forget to include the namespaces on your tag <html>:

xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"

  • I already used the example, but the address "/app/" will be deleted and my application will not find the url "localhost:8084/customer/service". I agree on the bad practice, however, I did not visualize a better and simple, if possible can inform me possible solutions.

  • I was analyzing the context, like ${pageContext.request.contextPath}, but since you considered not using it I will evaluate the suggested form.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.