日期:2014-05-18  浏览次数:20601 次

jsp中如何不跳转读取表单内容??
一般都是用form的action属性指定一个页面来读取form的内容,
有时候感觉这样很没有必要,代码很少却要创建一个新的文件。
有没有不跳转读取form内容的方法呢?
请指教!

------解决方案--------------------
<%@ page language= "java " contentType= "text/html; charset=ISO-8859-1 "
pageEncoding= "ISO-8859-1 "%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=ISO-8859-1 ">
<title> Insert title here </title>
<script language = "javascript ">
function post(){
var m = document.all.text1.value;
window.alert(m);
}
</script>
</head>
<body>
<form>
<input type= "text " name= "text1 " value= " ">
<input type= "button " name= "buttOne " value= "sss " onclick= "post() ">
</form>
</body>
</html>


你把东西输入文本框,可以存到变量m里面~~试试,不知道是不是你想要的效果...
------解决方案--------------------
1:可以跳转回来(sendredirect)
2:可以用AJAX
3:可以用JS
------解决方案--------------------
不知道lz是不是说的这个意思:(其实最好使用ajax)

<%@ page language= "java " import= "java.util.* " pageEncoding= "GBK "%>
<html>
<head>
<title> My JSP 'test.jsp ' starting page </title>
<meta http-equiv= "pragma " content= "no-cache ">
<meta http-equiv= "cache-control " content= "no-cache ">
<meta http-equiv= "expires " content= "0 ">
<meta http-equiv= "keywords " content= "keyword1,keyword2,keyword3 ">
<meta http-equiv= "description " content= "This is my page ">
</head>

<%
if (null != request.getParameter( "username ")&&
null != request.getParameter( "password "))
{
out.println( "name: " + request.getParameter( "username "));
out.println( "pwd: " + request.getParameter( "password "));
}
%>
<body>
<form action= " " method= "post ">
username
<input type= "text " name= "username " />
<br />
password
<input type= "text " name= "password " />
<br />
<input type= "submit " value= "提交 " />
</form>
</body>
</html>

------解决方案--------------------
用javascript实现.
document.forms[ 'formname '].elementname.value = newvalue;
------解决方案--------------------
直接 action= "本页.jsp " 没问题啊 我的就可以啊