• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
prasad boini
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2851
10
Fedora Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
prasad boini
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic