session,servlets,liferay,liferay-6,portlet , How to get Liferay login user details in servlet(Portlet)?

How to get Liferay login user details in servlet(Portlet)?


Tag: session,servlets,liferay,liferay-6,portlet

I have deployed my application as a porlet on Liferay, Now I need to perform session management while performing the business logic (in servlet). Let's say I have deployed my servlet on liferay.

I am using liferay 6.2, Tomcat 7, I am submitting one form to servlet before performing the business logic I need to check whether the request is coming from valid user OR Not. So I need to get the login user details for User authentication. How can I get the login user details in servlet? any suggestions?


You'll have to emulate whatever Liferay does in order to create the whole portlet context. IMHO it's not worth it for the scenario that you're giving. What's the problem of adding your servlet code to a portlet, where you have all of this context?

You can't really deploy a servlet "into Liferay" - your servlet might be running on the same application server as Liferay, but when you look at the HttpServletRequest's targets, you'll see that a servlet request is targetted to your servlet's web application, which is deliberately separated from Liferay - a totally different and unrelated application. When you look at a portlet request, it's directed to Liferay and then internally forwarded to your portlet in another web application. All this is well implemented already and IMHO not worth pursuing. The appserver will resist giving you all the data from another webapplication.

There are other solutions, but they all seem to be prohibitively complex compared to moving the servlet code into a portlet, that I'd wait for more arguments why you definitely need to keep with this implementation before I mention them.


Is it possible to share session between different PHP versions?

I am starting an old app refactoring, I will rebuild some functionality from spaghetti code to MVC (Symfony). Plan was I will set up new IIS app, using subdomain. Now, old app is running PHP 5.3 which can't be upgraded. New app will be running on PHP 5.6. Only thing...

How to use two port numbers for a single java web application?

I am working in a java web project in Eclipse IDE. project is working fine and we use Apache tomcat 7 as server. Now to access the application we use the URL as localhost:8080/APPNAME/. It works fine. In my project there is a servlet, that will request by other java...

after puttin php syntax, my website get stuck at preloader

I have this code on my php file for navbar: <?php if(!$session->is_logged_in()) { echo ' <a href="login.php" role="button" aria-expanded="false"> Login <span class="label"> login to system</span> </a> </li>';} else { echo ' <a href="#!" class="dropdown-toggle" role="button" aria-expanded="false"> ' . $session->user_name; . '<span class="badge bg-default">2</span> <span class="caret"></span> <span class="label">it is you</span> </a>';...

Devise prevent auto sign-in after registration

Here's my scenario : Users can register on my website by entering their university login. My app checks this login against the university LDAP, and if it exists, it will duplicate the university LDAP entry on my own LDAP + create a database entry for the user on the rails...

Is it a good practise store the checkout steps fields in php $_SESSION?

I have my e-commerce site with three checkout steps, each button to continue is a POST action and redirect to the next step: if the user navigates by the checkout steps (click on the previous button for example), the form fields don´t show the data posted previously. This form fields...

Downloading file from Java servlet gives null

I am trying to create a method that allows users to download a file on the file system via a Servlet. Right now, the correct filename shows on the download and a file is downloaded but the contents of the file are always null. I've also tried to get the...

How to open a new page when button is clicked on

The question is vague so allow me to clarify. I am developing a web app locally on eclipse and using Servlets, JSP, and an html document to design a web page. I have a home page which has two buttons, signup and login. I have one file, called index.jsp, which...

How to send automatic mail from java Servlet using gmail id?

I am trying to send an automatic mail from java servlet to the gmail id.i used the following class for it. import javax.mail.*; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import java.util.Properties; public class EmailTest { public void sendEmail(){ String to="[email protected]"; String host=""; final String user="[email protected]"; final String password="password"; //Get the session object...

CQ5 SlingServlet and resourceTypes not working for specific resource paths

If I define a Sling Servlet as follows: @SlingServlet( label="TestResourceTypeServlet", name = "", extensions = {"bob"}, resourceTypes= {"cq:Page"}, methods= {"GET"}, metatype=true) @Properties({ @Property(name = "service.description", value = "A test servlet"), @Property(name = "service.vendor", value = "Company") }) The servlet picks up any get request to every page with an extension...

How does a servlet handle more bytes than available RAM?

Lets say that I have a servlet running that accepts files of any size from a client application(s). The file being sent is loaded into a DataHandler and is transmitted by web-services; as such is received and put back into a DataHandler. What happens if the file being sent exceeds...

how to manage multiple war application in tomcat server?

I use tomcat as web server,I want to deploy many same war file in tomcat server with different config. How to do this in the best way possible manner? So I want to run tomcat server per each war application, my means is tomcat1 handle the .war1 in webapp and...

Print and println aren't executed in the same time

I have a method in my servlet where I have some prints to the console.. private void collectingWorkPositions(HttpSession session, HttpServletRequest request) { System.out.println("Collecting1.."); //code... System.out.println("Collecting2.."); //code... System.out.print("printing p: "); for(Integer i:p) System.out.print(i + " "); } When this method iscalled, only Collecting1.. Collecting2.. are printed in the console. When I...

Session Object is returning Null

public class FirstServletClass extends HttpServlet{ /** * */ private static final long serialVersionUID = -45872253821246793L; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException ,IOException { response.setContentType("text/html"); PrintWriter pw = response.getWriter(); HttpSession session = request.getSession(); if(request.getParameter("userName")!=null){ session.setAttribute("UserName", request.getParameter("userName")) ; } pw.print("HI From Server <br/>"); pw.print("Accessing Value...

How to include PHP $_SESSION values in a javascript file?

I use $_SESSION['siteRoot'] to store the root address of my website in (it's basically a framework so this can change depending on the URL used to access the site). I need to use this value in some of my javascript files... Up until now I've been including my js files...

How to Get The Parameters Name From The Http request

I want To Get The Parameters Name From My Http request, Please Give me the Solution, Thanks In advance

Java Servlet - get parameters with same name

I know that I can get parameter like: HTML <input type="text" name="field" value="test"> Servlet String field = request.getParameter("field"); But what if I have multiple input with same name like: HTML <input type="text" name="line[]" value="test1"> <input type="text" name="line[]" value="test2"> <input type="text" name="line[]" value="test3"> In PHP I can just use name="line[]" to...

Servlet to jsp on button click - whats the error?

I have a simple form on a jsp page, as given below. On clicking the button, it should take us to a servlet by the name of LoginValidation. But it doesn't work. <form name="login_form" action="LoginValidation" method="get" onsubmit="return func()" > <input type="text" placeholder="Username" id="username" class="style-4" /> <input type="password" placeholder="Password" id="pass" class="style-4"...

Force WWW when URL contains path using .htaccess

I'm having a problem with my URL and my sessions. I wish to have ALL website pages be forced to use www. As it looks like now, the website looks like this: into into into into (this is what's wrong) This is...

PHP Session Information Not Being Stored

I am trying to make a very simple website, where you can go to the main page and log in, of which the code is here <?php session_start(); $warning = $_GET['warning']; $nolog = $_GET['nolog']; $username = "Welcome, please log in"; if ($warning) { $username = "Wrong Username/Password Combination"; }...

Server side session in,web-services,session
I want to set one value in server side session in client side and need to access that session in web service, so i tried below In client side : //Set the server side session like below var vr_="demo.png"; '<%Session["path"] = "' + vr_ + '"; %>'; //In alert,checked the...

Login page filter problems

I'm trying to apply a filter to my login page. I'm just not sure how it works, since I'm not too familiar with filters. I'm trying to redirect a user that logs in to different pages based on their user type. A user has either the user type 'Customer', 'Owner'...

Authentication with OAuth and JWT but without OpenID Connect

I’m wondering if I really need OpenID Connect to provide authentication on top of OAuth2. It seems to me if I generate JWTs (JWE) as my access token and I store user claims, roles/permissions, etc. in the access token, then the OpenID Connect's id token isn't needed. Resource servers can...

Clicking Refresh Servlet Page Shows Repetitive Content

I am on my first servlet program and I have created a page to list the rows of a table from database. Whenever I click the refresh button, the page displays repeated results. How can I overcome it, any suggestions? @WebServlet("/BookList") public class BookList extends HttpServlet { private static final...

Logging DateTime in SQL Table When Users Session Ends

I have written an application and with this application the user has to login. I have a table where I am keeping their login token for that session, datetime they logged in, datetime they logged out and the duration in which they were logged in. This functionality works great when...

download jasper report to a specific location in the server

My application is running in a tomcat server, and I have already developed a method to download a pdf file using jasper. What i need to do is, download that certain pdf to a location inside the server. I tried and I am not sure how to do it. jasperReport...

OSX tmux configuration session open file in vim automatically

So I have tmux and vim running in iterm2 on OSX. I have a tmux.conf file that sources a session in ~/.tmux/ called 'left'. I have successfully loaded this session with three panes. Two panes in a left column and a single pane on the right. I have also managed...

SSL Handshake in Java Servlet (HttpsURLConnection)

I have a java web application that requires a servlet to open a connection with a url that returns some data in the form of JSON back to the servlet for processing. Traditionally this was done using an HttpURLConnection and everything worked as planned. Now, we have added as self-signed...

Store sensitive using Java Servlet API

I have web app which is running on Java Servlet web container,specifically on IBM WebSphere.My question is: whether there is the recommended way (as part of Java Servlet API) to store a sensitive data, like user password for example. I can write my own solution from scratch at any time,just...

How to transform $.post to $.ajax?

I have this $.post peace of code: $.post("../admin-login", { dataName:JSON.stringify({ username:uname, password:pass, }) }, function(data,status){ console.log("Data:"+data); answer = data; } ); and I wont to transform it to $.ajax. On the servlet side I am demanding request.getParamter("dataName") but I do not know how to write data: section in $.ajax so...

Symfony2: ajax call redirection if session timedout

I have a working dashboard with ajax request. I fire an ajax request on some events which will update a part of the dashboard. But if the session has expired, the part will be refreshed with the login page. How can i do a redirection after the ajax call if...

Disconnect Session via Powershell [closed]

Is there a command to disconnect a user from a session on a server via PowerShell? To logoff i use: Logoff /server:<Server> <SessionID> ...

get information in database and insert into session codeigniter

i am new to codeigniter and using session. i am having a problem in inserting individual data in session. Model: function get_user_info() { $user_email = $this->input->post('signin-email'); $this->db->select('acct_id, acct_fname, acct_lname, acct_mname'); $this->db->where('email', $user_email); $query = $this->db->get('account'); return $query->result_array(); } Controller: public function LoginValidation(){ $this->load->library('form_validation'); $this->form_validation->set_rules('email', 'Email',...

Tomcat servlet the requested resource is unavailable

I am very unfamiliar w/ servlets and have been asked to write a simple a simple program on tomcat 7 using java. I wrote a very simple hello world program and haven't been able to get it running and need some help. import*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*;...

How to share the same email session between all instances of the application?

Maybe this question is already answered, but I couldn't find the proper answer. I have a web application based in JSF, and I want to share the same email session between all the instances of the application, yet I haven't found how to do that. My questions are: a) What...

codeigniter session object expired availability

This might be a silly question. Once a user has been logged in, if session expires I want to redirect him to a "lockscreen" instead to a "login" page. I want to send to the lockscreen some session data (like img-src and loginname) So, here's the question. Does session object...

python-requests does not grab JSESSIONID and SessionData cookies

I want to scrape a pdf file from but it wants me to accept Terms and Conditions. While downloading from browser I found out that JSTOR saves my acceptance in 2 cookies with names JSESSIONID and SessionData but python-requests does not grab these two cookie( It grab two other...

html form action not working when using eclipse

I am new to JSP and Java Servlet. I was going through this tutorial by Java Brains. In this tutorial get and post method is handled. I wrote my html code under web-content. </head> <body> <form action="http://localhost:8080/SimpleServletProject/hello" method="post"> <input name="userName" /> <input type="submit" /> </form> </body> Following is the

Meteor: Passing Session values from client to server

I am using the following code on the client side to set the Session variable:{ 'click button': function() { var; UserSession.set("songsearcher", clientid); console.log(clientid + UserSession.get("songsearcher")); I am using the following pacakge: Meteor-User-session, which will explain the use of UserSession in place of Session. Now, this works fine. But...

How do you trigger session garbage collection in PHP < 5.4?

I need to force session garbage collection to trigger in PHP, and I'm using version 5.3.3. I see in PHP 5.4, you can call: SessionHandler::gc() What is the best method to get the same result given the PHP version I am using?...

Initialize class with constructor in

I am trying to initialize a class by passing a parameter to the constructor. I need the scope to be "page". I know I have one argument in my constructor, but how do I have one that accepts parameter using <jsp:useBean>, and can be called from a JSP page? public...

Distributed session implementation detail

With the reference to the structure of session module in ASP.NET below: As I understand, when the application uses distributed session provider (.e.g. Redis in Azure), the SessionStateModule will deserializes the user's session data into Session dictionary at the beginning of a request. What I'm wondering is whether the module...

how do i store these values into just one Session PHP

I have this variable that contains multiple values and I want to save all the values into a $_SESSION['gamecode']. It displays only the last value. $var=explode("|",$key); $gamecode=trim($var[0]); session_start(); $gc[]= trim($var[0]); $_SESSION['gamecode'][]=$gc; var_dump($_SESSION['gamecode']); EDITED foreach($_POST['gm'] as $key => $answer){ if($answer != ''){ $var=explode("|",$key); $gamecode=trim($var[0]); $_SESSION['gamecode'][]=$gc; var_dump($_SESSION['gamecode']); EDIT 2 foreach($_POST['gm'] as $key...

Trying to setup tomcat to use servlets

I'm following instructions found in Java All in one for Dummies 3rd edition I downloaded tomcat and followed all the steps for setting it up, step 6 says. "Modify the web.xml file to enable the invoker servlet" It says to find the lines of code for the invoker and then...


I am getting two PHPSESSID while printing $_SERVER['HTTP_COOKIE']. Actually I don't know how it is set twice, its only in my local system. When I check the SERVER cookie it like: echo $_SERVER['HTTP_COOKIE']; //result 'fe_toolbar=false; fe_toolbar=false; PHPSESSID=4tvbovcjk0msf9dvibeb31c2b7; langId=1; backendLangId=2; PHPSESSID=46aagg1hg7as2uh9bihjlpp8h7' When I check my cookie alone like : print_r($_COOKIE); //result...

Sending text file to client through Spring MVC web application

After doing some research online on the subject I currently managed to get things working with this code: @RequestMapping(value = "/report040Generated", method = RequestMethod.GET) public String index(Model model, HttpServletResponse response, HttpServletRequest request) throws IOException { String myString = "Hello"; response.setContentType("text/plain"); response.setHeader("Content-Disposition","attachment;filename=myFile.txt"); ServletOutputStream out = response.getOutputStream(); out.println(myString); out.flush(); out.close(); return...

Revert back to previous flask session variables when going back a page

On a Flask website of mine, I have a session variable called 'thisQuestion' which put simply increments by 1 each time a page is loaded. Basically, the page returns questions from a database and the user can state whether they get the question right or wrong. The session variable increases...

shall I use Spring framework for a performance-critical proxy application? [closed]

I've created a servlet (Tomcat) application which has these functions: It performs HTTP Basic Authentication. It connects to a user and role database. It works as "security facade" for some geodata servers behind It forwards requests after doing some authorization tests In case the response contains XML data, it performs...

session value in javascript cannot be set

I am quite new to javascript, I wonder why my session value in javascript wont be set to 1 even I tried. When call this function again, the value of the session will change again. My javascript code as below. <script type="text/javascript"> function Confirm() { alert(<%=Session["Once"]%> != 1); var value...

multiple SESSION cookies being set?

My site is sending two different session id cookies (PHPSESSID), one under "" and the other "". I read this answer here which says to specify the domain used in the 5th parameter, but what about SESSION cookies which are created automatically? I think the issue is that the facebook...

JSP form sending data including files in servlet

I am tryig to send some data from jsp form to a servlet. All my data are type="text" except from one that is type="file". I know that if i want to send the data to my servlet, i have to use request.getParameter(...). (My data) In order not to be null...