如何在不执行事件的情况下将值从JSP传递到Servlet? [英] How to pass values from JSP to Servlet without performing event?

查看:54
本文介绍了如何在不执行事件的情况下将值从JSP传递到Servlet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个portlet,在其中我在servlet中执行业务逻辑.但是我在jsp页面上获得了liferay登录用户的详细信息.因此,现在我需要在访问servlet时传递用户详细信息.这是我的JSP代码,

I have crated a portlet, Where I am doing my business logic in servlet. But I am getting the liferay login user details in the jsp page. So Now I need to pass the user details while hitting the servlet. This is my JSP code,

<%
 String fullname= user.getFullName();
 out.println("Full name is: "+fullname+ "...");
 long id = themeDisplay.getLayout().getGroupId();
 out.println("Site ID is: "+id+ "...");
 long userId = themeDisplay.getUserId();
 out.println("User ID is: "+userId+ "...");
 %>

我需要在servlet中访问以上详细信息.我怎样才能做到这一点?每个登录用户都有一些不同的凭据,因此所有值都应在servlet中进行更新并需要在servlet中进行访问.在不执行任何事件的情况下访问这些值的最佳方法是什么.我正在从另一个Web服务访问servlet.我需要在Get OR Post方法中访问

I need to access the above details in the servlet. How can I do that? Each login user has some different credentials, So all the values should update in and need to access in the servlet. what is the best way to access these values without performing any event. I am hitting the servlet from another web service. I need to access in Get OR Post method,

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                 doPost(request, response);
//I need to access those login user information here.. 
        }

推荐答案

这真的很难做到(几乎是不可能的"中的非常困难"):当您使用servlet时,所有门户网站的代码确定实际用户将无法运行.

This will be really hard to do ("really hard" as in "almost impossible"): When you're in a servlet, all the portal's code of identifying the actual user won't run.

实际上,当您查看HttpServletRequest的portlet时:这将直接指向门户,并且仅在以后使用正确构造的上下文(例如,登录用户)转发到portlet.

In fact, when you look at the HttpServletRequest for a portlet: This will be directed towards the portal and only later be forwarded to the portlet, with the properly constructed context (e.g. logged in user).

当您查看servlet时,它将直接指向您的servlet.您的servlet通常生活在完全不同的应用程序上下文中.因此,根据servlet规范,它将与门户环境完全分开.

When you look at the servlet, this will be directed to your servlet. Your servlet typically lives in a totally different application context. Thus - by servlet specification - it will be totally separated from the portal environment.

您发现减轻此限制的所有内容都会有些骇人听闻.有些人使用cookie或请求参数.但是他们都或多或少地引入了问题.尤其是当谈到访问您的servlet的Web服务时,就无法使用Cookie.

Everything that you find to mitigate this limitation will be somewhat of a hack. Some people use cookies or request parameters. But they all are introducing more or less problems. Especially when you speak of webservices that access your servlet, you can't go with cookies.

为了实现一个易于维护的实现,我的建议是更改您的体系结构.不幸的是,您没有提供足够的上下文来建议将体系结构更改为什么.

In the interest of a well maintainable implementation, my recommendation is to change your architecture. Unfortunately you don't give enough context to recommend what to change your architecture to.

这篇关于如何在不执行事件的情况下将值从JSP传递到Servlet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆