在一个JSP页面POST一个表单后然后根据返回值输出信息,怎么搞?

superxs 2006-04-28 04:23:19
在一个页面POST一个表单后然后根据返回值输出信息,怎么搞?
...全文
1049 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
commuter 2006-05-04
  • 打赏
  • 举报
回复
在要显示信息的地方插入参数名,没有就不显示。
liboyang 2006-05-02
  • 打赏
  • 举报
回复
噢也学习
xiongbing528 2006-05-02
  • 打赏
  • 举报
回复
基本是这样的
a.jsp
<input type="text" name="logname"/>
b.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<fmt:requestEncoding value="gb2312">
<c:out value="${param.logname}"/>
ruanjiantaotao 2006-05-02
  • 打赏
  • 举报
回复
回答:
含表单的页面,里面定义变量如name,sex,这些都是控件的名字,
提交后用request.getParameter("name")和request.getParameter("sex")获取参数值,OK
天地客人 2006-04-29
  • 打赏
  • 举报
回复
学习!
ruanjiantaotao 2006-04-28
  • 打赏
  • 举报
回复
回答:使用request.getParameter("参数"),参数是你在需传递页面中定义的变量,如你自己定义的Name和Sex
killme2008 2006-04-28
  • 打赏
  • 举报
回复
ajax调用吧,不刷新页面异步提交,参数通过URL后缀传递
var xmlhttp=new ActiveXObject("Micorsoft.XMLHTTP");
xmlhttp.Open("POST",url,false);
xmlhttp.Send("");
if(xmlhttp.responseText=="ok"){
.....
}
南南北北 2006-04-28
  • 打赏
  • 举报
回复
1.jsp
<%
//取值
String username = request.getParameter("username");
//判断

if(username!=null&&username.length>0&&username.equals("j2ee")){
String isLogin="ok"; //为什么不返回一个boolean值呢.楼主
session.setAttribute("username",username);
session.setAttribute("isLogin",isLogin);
}
response.sendRedirect("2.jsp");
%>

2.jsp
//<form action="1.jsp" method="get">....略
<%
String isLogin = session.getAttribut("isLogin");
if(isLogin!=null&&isLogin.length>0&&isLogin.equals("ok")){
String username=session.getAttribut("username");
out.print(username);
}
%>
以上是两个jsp页面之间传值,使用session对象
也可以使用request对象或者url重写
lcllcl987 2006-04-28
  • 打赏
  • 举报
回复
ajax
superxs 2006-04-28
  • 打赏
  • 举报
回复
如果是POST数据后,自己可以写收到POST数据以后的处理,那会很简单,问题是POST以后的界面是别人写的,我这管不了,而我还要继续执行我得动作,怎么返回来
superxs 2006-04-28
  • 打赏
  • 举报
回复
在一个页面做表单POST,到了另外一个页面B,如果参数争取,页面B返回OK,我就根据这个值执行PRINT
xt12822121 2006-04-28
  • 打赏
  • 举报
回复
<%if(case1){%>
<div>info1</div>
<%}else{%>
<div>info2</div>
<%}%>
cliu0207 2006-04-28
  • 打赏
  • 举报
回复
这是我自己编的一个小程序,功能是用户注册,然后将注册信息显示在调用的JSP页面上.楼主可以参考一下。
<html>
<head>
<title>用户登记</title>
<meta http-equiv="Content-Type" content="text/html;charset=GB2312">
</head>

<body>
<center><font size="5">用户登记</font></center>
<hr>
<form action="writeIntoDB.jsp" method="post">
<p>姓名:<input type="text" name="Name" maxlength="20"><font size="2" color="red">*不能超过20个字符</font>
<p>性别:<input type="radio" name="Sex" value="male" checked>男
<input type="radio" name="Sex" value="female">女<font size="2" color="red">*</font>
<p>密码:<input type="password" name="Password" maxlength="20"><font size="2" color="red">*不能超过20个字符</font>
<p>地址:<input type="text" name="Address" maxlength="20"><font size="2" color="red">*</font>
<p>出生日期:<input type="text" name="Birthday" maxlength="20"><font size="2" color="red">*格式如1981-01-02</font>
<p><input type="submit" value="提交">
<input type="reset" value="重置">

</body>
</html>

JSP代码如下:
<%@page contentType="text/html;charset=gb2312" language="java"%>
<%request.setCharacterEncoding("gb2312");%>

<html>
<head>
<title>显示提交结果</title>
</head>

<body>
<%
String name=request.getParameter("Name");
String sex=request.getParameter("Sex");
String password=request.getParameter("Password");
String address=request.getParameter("Address");
String birthday=request.getParameter("Birthday");
%>

姓名:<%=name%><br>
密码:<%=password%><br>
性别:<%
if(sex.equals("male"))
out.println("男");
else out.println("女");
%><br>
地址:<%=address%><br>
出生日期:<%=birthday%><br>

</body>
</html>

我的源程序原本还有将用户信息写入数据库的动作,已经让我删除了。
楼主可以看到,在HTML和JSP页面中进行通信,很类似于函数参数的传递.
feng1071 2006-04-28
  • 打赏
  • 举报
回复
楼主,可以说明白点?
Marcus-Z 2006-04-28
  • 打赏
  • 举报
回复
楼主说明白点啊!

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧