Url changed in spring

189 views Asked by At

I have a from and when the form is filled and submitted I wanted the request to be http://localhost:8080/restroo/admin/adminLog but it gives http://localhost:808/adminLogand getting 404 error. I don't know why I am having this problem and actually I was having problem in using two controllers in spring.

web.xml

<servlet>  
<servlet-name>spring</servlet-name>  
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-
class>  
<load-on-startup>1</load-on-startup>  
</servlet>  
<servlet-mapping>  
<servlet-name>spring</servlet-name>  
<url-pattern>/</url-pattern>  
</servlet-mapping> 
</web-app>  

I have spring-servlet.xml

admin.jsp

 <form method="post" action="/adminLog" modelAttribute="adminUser">
     First Name: <input type = "text" name = "userName">
     <br />
     password <input type = "password" name = "password" />
     <input type = "submit" value = "Submit" />
  </form>

AdminPageController.java

@Controller
@RequestMapping("/admin/*")
public class AdminPageController {
@Autowired
AdminUser adminUser;
@Autowired
MenuItems menuItems;
@Autowired
MenuItemsDao menuItemsDao;
@Autowired
AdminLoginDao adminLoginDao;
@RequestMapping(value="", method=RequestMethod.GET)
public ModelAndView addMenuItems(@ModelAttribute MenuItems menuItems){
//      if(menuItems != null){
//          menuItemsDao.addItems(menuItems);
//      }
    return new ModelAndView("admin");

}
@RequestMapping(value="/adminLog", method=RequestMethod.POST)
public ModelAndView adminLogin(@ModelAttribute("adminUser") AdminUser ad){
     List<AdminUser> adminUser = adminLoginDao.adminLogin();
     int len = adminUser.size();
     for(int i=1;i<=len;i++){
         String userN = adminUser.get(i).getUserName();
         String pass = adminUser.get(i).getPassword();
         if(userN.equals(ad.getUserName()) && (pass.equals(ad.getPassword()))){
              return new ModelAndView("adminLogin");    

            }
     }  
                return new ModelAndView("admin");

}


}
2

There are 2 answers

3
Mykola Yashchenko On

You have to change servlet mapping by adding a prefix for the API of the whole app:

<servlet-mapping>  
    <servlet-name>spring</servlet-name>  
    <url-pattern>/restroo</url-pattern>  
</servlet-mapping> 
1
Sri Ni VAsu Yemineni On

You are using Internal Resource View Resolver It is not able fetch view Not In Web-INF Floader.

Find This http://www.baeldung.com/spring-mvc-view-resolver-tutorial.