您应该研究使用Ajax(jQuery是我的首选方法)。
http://api.jquery.com/jQuery.get/
http://api.jquery.com/jQuery.post/
然后,这将命中一个控制器,该控制器将返回您想要的数据而无需刷新页面。
例如,如果您有一个login.jsp …
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %><%@ page session="true" %><html><script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script><head> <title>Login</title></head><body><h1> Hello please login to this application </h1><script> function login(){ var username = $("#username").val(); var password = $("#password").val(); $.post('login', { username : username , password : password }, function(data) { $('#results').html(data).hide().slideDown('slow'); } ); }</script>Username : <input id="username" type="text" />Password : <input id="password" type="password" /><input name="send" type="submit" value="Click me" onclick="login()" /><form name="next" action="auth/details" method="get"> <input name="send" type="submit" value="Go Through"/></form><div id="results" /></body></html>在您的控制器中,您将选择模型,但是为了简单起见,我做了一个非常简单的示例…
@Controllerpublic class LoginController { private static final Logger logger = LoggerFactory.getLogger(LoginController.class); Util util; @RequestMapping(value = "/login", method = RequestMethod.POST) public String home(Locale locale, Model model, String username, String password) { if(username.equalsIgnoreCase("david")) { model.addAttribute("validUser", "Welcome " + username ); return "home"; } else { model.addAttribute("validUser", "Incorrect username and password"); return "home"; } }}然后,这会将html的慢速滚动位添加到div,以表明它是否有效,下面是home的代码…
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %><%@ page session="true" %><html><body><P> ${validUser}. </P></body></html>


