title: block a direct call to a controller
body: <p>I'm working on a website using JAVA Spring mvc. I have a functionality that requires two controllers. First of all, the request is handled by controller1 who redirect it to controller2 using a return new ModelAndView ("redirect:controller2.htm"). All is working fine. However,I would like to block the direct access to the controller2 ( block a call from the  url "controller2.htm") because the controller2's form needs data from the controller1.I want that the only case in which controller2 is used is the redirection from controller1. I would like a solution without annotations.Thanks in advance for your help.
  Here is the code :
  Controller1:</p>
  
  <pre><code>public class controller1 extends SimpleFormController implements Serializable {
  private PersonManager pManager ;   
  @Override
  public ModelAndView onSubmit(Object command) {
      CommandPerson cmd = (CommandPerson) command;
      Person p = null;
          String viewName = "redirect:controller2.htm";
          try {
              p = pManager.getPersonbyID(cmd.getID());
          } catch (EmptyResultDataAccessException ex) {
        viewName="NosuchPerson";
          }
         ModelAndView mav = new ModelAndView(viewName);
          mav.addObject("ID",cmd.getID());   
          return mav;
   }
  </code></pre>
  
  <p>controller2:</p>
  
  <pre><code>  public class controller2 extends SimpleFormController implements Serializable {
      private PersonManager pManager ;   
      @Override
      public ModelAndView onSubmit (Object command) throws ServletException, IOException { 
  
            Person p = (Person) command;
           Map&lt;String,Object&gt; model = new HashMap&lt;String,Object&gt;();
                  pManager.UpdatePerson(p);
                  model.put("person", p);
                 return new ModelAndView("SuccesfulUpdate","model",model);
  
          }
  
      protected Object formBackingObject(HttpServletRequest request,HttpServletResponse response)
               throws ServletException, IOException {
                          String  id = request.getParameter("ID");
                          if(id==null) {
                              response.sendRedirect("controller1.htm");
                              return null;
                          } else{
                      Personne p = pManager.getPersonbyID(id);
                            return p;
                  }}
  </code></pre>
  
  <p>If the url "controller2.htm" is called directly the ID parameter will be null,and as the formBackingObject() is the first method executed when the request is being handled I thought I could  make a redirection in it , but it didn't work as I'm redirected to the controller2's form being empty.</p>