在jsp页面如何把javascrip的数据放到jsp的session对象中

2025-01-29 14:09:57
推荐回答(2个)
回答1:

jsp中可以把js变量存入session的。
简单描述:调用JS方法获取数据A,将数据A传给JSP上,通过sesison.setAttribute("A",A);就放到sesion对象中了。
用ajax可以跟jsp直接交互的。

回答2:

class Transfer
{
public String payAccounts;
public String AcceptAccounts;
public String AcceptName;
public double money;
public int tradeId;
public int UserID;
public String date;
public String Currency;
public double charges;
}
在jsp1页面
Transfer ts=new Transfer();
ts.payAccounts= (String) request.getParameter("payaccounts");
ts.AcceptName= (String) request.getParameter("newaccname");
ts.AcceptAccounts= (String) request.getParameter("AcceptAccounts");
ts.money= Double.parseDouble((String) request.getParameter("txtTranAmt"));
ts.Currency= (String) request.getParameter("Currency");
//获取当前时间
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
java.util.Date currentTime = new java.util.Date();//得到当前系统时间
String str_date1 = formatter.format(currentTime); //将日期时间格式化
String str_date2 = currentTime.toString(); //将Date型日期时间转换成字符串形式
ts.date=str_date2;
//计算费用
ts.charges=ts.money*0.001;
if (ts.charges>20)
{
ts.charges=20;
}
session.setAttribute("tstemp",ts);
在jsp2页面想调用session中的tstemp
Transfer ts=(Transfer)session.getAttribute("tstemp");
结果一运行总出错:
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /vrbankjsp/WebRoot/tradeeztoken.jsp at line 7

4: //transfer ts=new transfer();
5: //session.setAttribute("tstemp",ts);
6:
7: Transfer ts=(Transfer)session.getAttribute("tstemp");