简体   繁体   English

如何在不执行事件的情况下将值从JSP传递到Servlet?

[英]How to pass values from JSP to Servlet without performing event?

I have crated a portlet, Where I am doing my business logic in servlet. 我创建了一个portlet,在其中我在servlet中执行业务逻辑。 But I am getting the liferay login user details in the jsp page. 但是我在jsp页面上获得了liferay登录用户的详细信息。 So Now I need to pass the user details while hitting the servlet. 因此,现在我需要在访问servlet时传递用户详细信息。 This is my JSP code, 这是我的JSP代码,

<%
 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+ "...");
 %>

I need to access the above details in the servlet. 我需要在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. 每个登录用户都有一些不同的凭据,因此所有值都应在servlet中进行更新并需要访问。 what is the best way to access these values without performing any event. 在不执行任何事件的情况下访问这些值的最佳方法是什么。 I am hitting the servlet from another web service. 我正在从另一个Web服务访问servlet。 I need to access in Get OR Post method, 我需要在Get OR Post方法中访问

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

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. 这将真的很难做到(“几乎不可能”中的“非常困难”):当您在servlet中时,标识实际用户的所有门户网站代码都不会运行。

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 (eg logged in user). 实际上,当您查看HttpServletRequest的portlet时:这将直接指向门户,并且仅在以后使用正确构造的上下文(例如,登录用户)转发到portlet。

When you look at the servlet, this will be directed to your servlet. 当您查看servlet时,它将直接指向您的servlet。 Your servlet typically lives in a totally different application context. 您的servlet通常生活在完全不同的应用程序上下文中。 Thus - by servlet specification - it will be totally separated from the portal environment. 因此,根据servlet规范,它将与门户环境完全分开。

Everything that you find to mitigate this limitation will be somewhat of a hack. 您发现减轻此限制的所有内容都会有些骇人听闻。 Some people use cookies or request parameters. 有些人使用cookie或请求参数。 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. 特别是当谈到访问您的servlet的Web服务时,就无法使用Cookie。

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. 不幸的是,您没有提供足够的上下文来建议将架构更改为哪些内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM