File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes How To Use Session Scope Data In a Different Web-Application? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How To Use Session Scope Data In a Different Web-Application?" Watch "How To Use Session Scope Data In a Different Web-Application?" New topic
Author

How To Use Session Scope Data In a Different Web-Application?

prasad boini
Greenhorn

Joined: Nov 22, 2012
Posts: 8
ticketbookingapp:
===================
package com.ticketbookingapp.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ticketbookingapp.dto.UserInfo;

public class BookTicketServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String name = request.getParameter("username");
String password = request.getParameter("password");
System.out.println(name);
System.out.println(password);

UserInfo info = new UserInfo();// Instantiating DTO
info.setName(name);
info.setPassword(password);

HttpSession session = request.getSession();
session.setAttribute("details", info);

response.sendRedirect("http://prasad-pc:8080/xxxxbankapp/index.jsp");//Redirecting To Another Application Which Is Running On Same Server....From xxxxbankapp index.jsp, When Click On Submit It Invokes ValidateUserDetails Servlet...
}

}
=============
xxxxbankapp:
============

package com.xxxxbankapp.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ticketbookingapp.dto.UserInfo;

public class ValidateUserDetails extends HttpServlet {

private static final long serialVersionUID = 1L;

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

HttpSession httpSession = request.getSession(false); //Here I am Getting Session Object...
if (httpSession != null) {
System.out.println("Got Session Object..");
UserInfo info = (UserInfo) httpSession.getAttribute("details");

if (info != null) { // Here I unable to get Userinfo Object
System.out.println("Got UserInfo Object...");
System.out.println(info.getName());
System.out.println(info.getPassword());
request.getRequestDispatcher("/userLoginSucess.jsp").forward(
request, response);
} else {
request.getRequestDispatcher("/userLoginFailure.jsp").forward(
request, response);
}
}else{
System.out.println("Unable Get Session Object..");
}

}

}
output:
Got Session Object.. and It Will Redirect to userLoginFailure.jsp...

I want To Send Data from ticketbookingapp to xxxxbankapp in secure way.. How Can I Send?


Thank You Very Much For spending Your Valuable Time .
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2718
    
    6

The session scope cannot surpass the application scope. So there is no scope shared by multiple applications, even on same server.
You can add the field in the request and submit the request to the second application, send it as hidden field, query parameter,etc.

Only making use of session does not make the data transfer "secure". It should be using SSL, or field encryption for sensitive fields.

SCJP, SCWCD.
|Asking Good Questions|
prasad boini
Greenhorn

Joined: Nov 22, 2012
Posts: 8
 
 
subject: How To Use Session Scope Data In a Different Web-Application?