我目前已经为我的索引页面构建了一个控制器,它也是一个登录页面。使用控制器,如果用户的登录凭据匹配,我将映射 jsp,如果不匹配,我想重定向到带有消息“抱歉用户名,密码错误”的索引页面。这是代码:控制器if(uname.equals(inf.getUsername())&&pwd.equals(inf.getPassword())&&dept.equals(inf.getDept())) { req.getSession().setAttribute("uname",inf.getName()); return new ModelAndView("employeeLoginResult", "message", message1); } else if(uname.equals(inf2.getUsername())&&pwd.equals(inf2.getPassword())&&dept.equals(inf2.getDept())) { req.getSession().setAttribute("uname",inf2.getName()); return new ModelAndView("adminLoginResult", "message", message2); } else { return new ModelAndView("redirect:/index.jsp","message","Sorry"); }索引页<b><span class="heading">LOGIN USER</span></b> <div class="container"> <form action="login.html" method="Post"> <div class="form_style"> <input type="text" name="username" placeholder="Enter Username"/> <input type="password" name="pwd" placeholder="Enter password"/> <select name="dept"> <option>IT</option> <option>Admin</option> <option>HR</option> <option>Marketing</option> </select> <input type="Submit" value="submit"> <span class='disp'>${message}</span> </div> </form> </div>重定向有效,但消息会像这样附加在 Url 中:我只想用 ${message} 在索引文件上打印“对不起用户名密码错误”我的问题:是否可以将 ModelAndView 与 RedirectView 一起使用,或者如果没有其他解决方案可以使用 ModelAndView 将重定向发送到我的索引页?任何建议或意见表示赞赏。感谢同样的。
2 回答
呼啦一阵风
TA贡献1802条经验 获得超6个赞
你能添加一个像 MyConfig 这样的类吗
@EnableWebMvc
@Configuration
public class MyConfig {
@Autowired
private RequestMappingHandlerAdapter requestMappingHandlerAdapter;
@PostConstruct
public void init() {
requestMappingHandlerAdapter.setIgnoreDefaultModelOnRedirect(true);
}
}
添加回答
举报
0/150
提交
取消