Java jspajax成功重定向到另一个JSP页面
对于JSP来说,这是一个非常新的概念。 我的index.jsp中有以下代码Java jspajax成功重定向到另一个JSP页面,java,jsp,servlets,Java,Jsp,Servlets,对于JSP来说,这是一个非常新的概念。 我的index.jsp中有以下代码 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>AJAX Form</title>
</head>
<body>
<form method="POST" id="form1" onsubmit="return validateLoginForm()" >
UserName: <input type="text" name="username" id="username">
<br />
Password: <input type="text" name="password" id="password"/>
<input type="submit" value="Submit" />
</form>
<p id="demo"></p>
</body>
</html>
<script type="text/javascript">
function validateLoginForm() {
var url = "action_form_process.jsp";
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
var params = { "username":username,
"password":password
};
http.open("POST", url, false);
http.setRequestHeader("X-Requested-With","XMLHttpRequest");
http.setRequestHeader("Content-type", "application/json");
http.send(JSON.stringify(params));
return true;
}
</script>
AJAX表单
用户名:
密码:
函数validateLoginForm(){
var url=“action\u form\u process.jsp”;
var username=document.getElementById(“用户名”).value;
var password=document.getElementById(“密码”).value;
var params={“username”:username,
“密码”:密码
};
http.open(“POST”,url,false);
setRequestHeader(“X-request-With”,“XMLHttpRequest”);
setRequestHeader(“内容类型”、“应用程序/json”);
http.send(JSON.stringify(params));
返回true;
}
还有另一个JSP“action\u form\u process.JSP”
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Form Processing</h1>
<p><b>Welcome User: Coder</b>
</p>
</body>
</html>
在此处插入标题
表格处理
欢迎用户:编码器
但重定向不会发生。
完全没有错误。所有JSP都在同一个文件夹中
请帮助并解释我做错了什么?为什么要使用AJAX?我的实时应用程序中有很多问题。这只是我正在尝试的一个片段。我必须使用AJAX onlyOk来实现它,但是我看不到您重定向的代码。您应该将代码放入一个servlet中,在那里可以处理
POST
。不确定,但我猜JSP页面在默认情况下是一个GET
。@soorapadman我承认这一点。事实上,我不太确定如何做到这一点。我已经提到了另一个jsp名称作为url,它应该自动重定向到该jsp,还是我还必须做其他事情?