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/adminLog
and 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");
}
}
You have to change servlet mapping by adding a prefix for the API of the whole app: