gpt4 book ai didi

tomcat - 使用 ssionId 和 URL 参数而不连接它们

转载 作者:行者123 更新时间:2023-11-28 23:37:43 26 4
gpt4 key购买 nike

我有这样一个网址:

"http://mydomain.com/aservlet/?id=auniqueId;jsessionid=ABCDEFGHIJK "

现在在我的 servlet 中,当我检索参数时:

String id = request.getParameter("id");

id 参数将为 auniqueId;jsessionid=ABCDEFGHIJK

我想要的是auniqueId

问题是,我不知道最后一个参数是什么,所以我必须解析所有参数的“;”先签名,然后删除它,然后我才能使用它们。

这真的有必要还是有更干净的解决方案?

最佳答案

我假设你已经完成了所有这些步骤,或者如果你还使用了其他 impl 和 import *,请试试这个。

好的..你需要这样的“http://mydomain.com/aservlet/jsessionid=ABCDEFGHIJK&&id=uniqueid

您需要在您的 servlet 操作上将 HttpServletRequest req 作为参数。

Then 

try
{
HttpSession ssn = req.getSession(); //try to handle servle exceptions too
String ssnId = ssn.getId();
System.out.println(ssnId); //check for null first on your real code

}
catch(Exception ex){
System.out.println("Exception "+ex.getMessage());
}

OutPUt: ABCDEFGHKLL; //only the id part not the jsession string

关于tomcat - 使用 ssionId 和 URL 参数而不连接它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23105349/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com