【发布时间】:2015-02-22 01:12:33
【问题描述】:
我想从登录页面重定向到主页(.jsp),我想在主页中显示登录的值,我使用了 window.location.replace 但主页中的值为“null”.in我第一次将数据发送到 servlet 并且 servlet 重定向到主页。
登录.html
<form>
<p><input type="text" id="login" ></p>
<p> <input type="button" value="LOGIN" id="log" ></p>
</form>
login.js
$(document).ready(function (){
$("#log").click(function (){
var log = $("#login").val();
$.post("Test",{log:log},function(){
}).success(function (){
window.location.replace("Test?log="+log) ;
});
servlet:Test.java
String l =request.getParameter("log");
request.setAttribute("l", l);
getServletContext().getRequestDispatcher("/home.jsp").forward(request,response);
home.jsp
<body>
<% out.println(request.getAttribute("l")) ; %>
</body>
谢谢。
【问题讨论】:
-
将文本添加到会话中。这也是在其他页面上发送数据的一种方式。
-
你想达到什么目的?您可以简单地将 login.html 提交到 home.jsp 以获得登录值。
-
我想使用servlet作为控制器,所有的html页面都向servlet发送请求,servlet重定向到不同的页面
标签: java javascript jsp servlets