【发布时间】:2013-11-21 18:03:06
【问题描述】:
我在 spring mvc3 中使用 session 时遇到问题。我不知道如何使用它。当我点击按钮提交时..它不起作用......我只是spring mvc的新手...... 这是我的示例代码:
登录控制器:
@Controller
@SessionAttributes({"account"})
public class LoginController {
@Autowired
private CatalogService catalogSerivce;
@Autowired
private AccountService accountSerivce;
@RequestMapping(value = "/login")
public String list(Model model) {
List<Catalog> listCatalog = catalogSerivce.getListCatalog();
model.addAttribute("catalogs", listCatalog);
return "login";
}
@RequestMapping(value = "/login", method = RequestMethod.POST)
public ModelAndView login(@RequestParam(value = "tbusername") String username,
@RequestParam(value = "tbpassword") String password,
@ModelAttribute(value = "account") Account account) {
ModelAndView modelAndView = new ModelAndView();
account = accountSerivce.authenticate(username, password);
modelAndView.addObject("account", account);
return new ModelAndView("index");
}
}
索引控制器
@Controller
@SessionAttributes({"account"})
public class IndexController {
@Autowired
private CatalogService catalogSerivce;
@Autowired
private ProductService productService;
@RequestMapping(value = {"/index", ""})
public String list(Model model){
List<Catalog> listCatalog = catalogSerivce.getListCatalog();
List<Product> listProduct = productService.searchProductByCatalog("", "");
model.addAttribute("catalogs", listCatalog);
model.addAttribute("products", listProduct);
return "index";
}
}
login.jsp
<form action='login' method='post'>
<label>Username</label> <input type='text' class='field'
name='tbusername' /> <label>Password</label> <input
type='password' class='field' name='tbpassword' />
<input type='submit' class='search-submit' name='login'
value='Login' />
<p>
<a href='register' class='bul'>Don't have an account</a><br />
</form>
【问题讨论】:
-
这里有什么问题?
-
我不知道什么时候点击按钮登录,它不起作用...它没有收到索引中的会话
-
我尝试调试但它没有跳转到方法登录...
标签: java spring session spring-mvc