我需要在Java Web应用程序中进行make会话.
我发现sesstion通过方法getSession()在servlet calass中生成.
但我有一个关于会话参数的问题.例如,我发送到服务器登录/传递并将其保存到会话属性中.好.下次我在客户端做一些事情并将新的params发送到服务器.我要去哪里?在另一个或相同,我将使用if else这样的句柄参数?
另一个问题:如何使用我在其他课程中进行会话(登录/通过)的参数?
UPDATE
我读了大约sessions.并有新的问题.如何在enother类中使用session params.我的意思是在登录后我在服务器上发送新的参数,在servlet中读取它并希望从会话中获取登录/传递并将其与新参数一起发送到另一个类.
解决方法:
作为doGet或doPost方法中请求处理的一部分,以下是如何获取会话并使用它来获取和设置变量的方法.
//Obtain the session object, create a new session if doesn't exist
HttpSession session = request.getSession(true);
//set a string session attribute
session.setAttribute("MySessionVariable", "MySessionAtrValue");
//get a string sessson attribute
String strParam = session.getAttribute("MySessionVariable");
//get an integer sessioin attribute
Integer param = (Integer) session.getAttribute("MySessionVariable");
//set an integer session attribute
session.setAttribute("MySessionVariable", new Integer(param.intValue() + 1));
标签:java,web-applications
来源: https://codeday.me/bug/20190831/1779189.html