How to maintain session in jsp
Hello Techies,
I am very new jsp and doing xperimentation in jsp. I am having 3 jsp's namely a.jsp,b.jsp,c.jsp.
In b.jsp I am having one combo box , after selecting the combo box I want to put the value in session.
How can I do this one.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page language="java" contentType="text/html; charset=iso-8859-1" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript">
function ll() {
alert("test");
// var sel=document.forms[0].rule;
document.forms[0].submit();
alert("form is submitted")
</script>
</head>
<body>
<select name="comboBox" size="1" onchange="ll()">
<option value="">1</option>
<option value="">2</option>
<option value="">3</option>
</select>
</body>
</html>How can I set the selected value in this combo box into session.
Can u guys help me out in fixing this problem.
Well you have to submit the form first.
In the java code:
String comboValue = request.getParameter("comboBox");
session.setAttribute("comboValue", comboValue);
Similar Messages
-
Hi,
I am having trouble in maintaining session in jsp frames. -
Here is sample code
parent.jsp
<HTML>
<HEAD>
<LINK rel=stylesheet type="text/css" href="defaults.css">
<TITLE>abc</TITLE>
<%
String checkAmount = "100.00";
session.setAttribute("checkAmount", checkAmount);
System.out.println("checkAmount in ppmain"+session.getAttribute("checkAmount"));
%>
<FRAMESET rows="235,*" frameborder="no" >
<FRAME NAME="pptop" SRC="top.jsp" frameborder=0 scrolling=no noresize >
<FRAME NAME="ppbottom" SRC="bottom.jsp" frameborder=0 scrolling=no marginwidth=0 marginheight=0 noresize>
</FRAMESET>
</HTML>
top.jsp -
<HTML>
<HEAD>
<LINK rel=stylesheet type="text/css" href="defaults.css">
<TITLE>top</TITLE>
<%
System.out.println("session in top "+session);
System.out.println("checkAmount in top "+session.getAttribute("checkAmount"));
%>
</HTML>
It is not able to retain session in the top.jsp ( in SOP for session I get different session ID in parent.jsp and top.jsp
This Works well in local but when gets deployed to WAS6 server troubles starts.
Any help is appreciated.
ThanksWhen you create URLs, you might want to try using JSTL to rewrite them:
<FRAME NAME="pptop"
SRC="<c:url value='top.jsp'/>"
frameborder=0
scrolling=no
noresize >
<FRAME NAME="ppbottom"
SRC="<c:url value='bottom.jsp'/>"
frameborder=0
scrolling=no
marginwidth=0
marginheight=0
noresize>Or you can use:
SRC='<%= response.encodeURL("top.jsp") %>' -
How to clear session in JSP?
I searched yahoo, and found that it seemed not easy to force invalid the session using jsp, compared to php just three lines:
session_start();
session_unset();
session_destroy();
How to acheive this using JSP? Must I follow these (quite complex) steps like this one?
http://sdc.sun.co.jp/javasystem/technote/cluster/jsp.html
Any simplier method?
Thx.Not at all, it's very simple.
<%
session.removeAttribute("attributeName");
%>
This HttpSession API document shows all methods that can be called on the session object : http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpSession.html -
How to create session in JSP & Servlet
Hi All
I'm really new to JSP & Servlet. So I want to know how to create sessions and how to pass details to another web page
Thanks
PadmaYou can easily pass objects from one jsp or servlet to another.
On your servlet execute method (for example), you can do this as follows:
HttpSession session = request.getSession();
User u = new User();
session.setAttribute("user", u);And get it again on other servlets:
HttpSession session = request.getSession();
User user = (User) session.getAttribute("user");I hope this helps you. -
How to maintain Session between two ear files?
HI Guys
I have deployed two ear files in oc4j. One is used to open applet and other for business operations.
My problem is after calling applet my session gets invalidate. How to save session between two context
I am new in this field please help!!
the sooner the better
RahulCan I do this if I integrate oc4j with apache!!
Can I maintain session
Plz. Help
Rahul -
Maintain session in JSP after using filters
I have to extend this application to maintain the session , because there are 10 jsp pages in my application.
When the user logs in , and hits a tab(which should redirect to another jsp page - assume users.jsp) the page is redirected back to the login page (instead of the users.jsp page) because of the filter.
How do I maintain the session here , so that a user who is logged in (with user name and password) could access the other pages instead of just being redirected back to the login.jsp page.
this is my filter page
package com.bea.genesis.tenantmgmt.utils;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class FacesRedirectFilter implements Filter {
public void doFilter(ServletRequest req,ServletResponse res,FilterChain chain)
throws ServletException, IOException
HttpServletRequest request = (HttpServletRequest)req;
HttpServletResponse response = (HttpServletResponse)res;
//String uri = request.getRequestURI();
String relativePath = request.getServletPath();
if ((relativePath.indexOf("/pages/") >= 0) && relativePath.endsWith(".jsf")) {
//int length = uri.length();
//String newAddress = uri.substring(0, length-3) + EXTENSION;
//response.sendRedirect("login.jsf");
RequestDispatcher rd = request.getRequestDispatcher("login.jsf");
rd.forward(req, res);
chain.doFilter(request, response);
public void destroy() {
// TODO Auto-generated method stub
public void init(FilterConfig filterConfig) throws ServletException {
// TODO Auto-generated method stub
Please reply
thanksThanks for the reply , How do I test in the filter whether the user is loged in or not.(I dont have clue , how to do tht)
this is my login Bean ---
import java.util.Map;
import javax.faces.context.FacesContext;
public class LoginBean extends AbstractBean {
private String loginId;
private String password;
private LoginService loginService;
private LoginValidator loginValidator = new LoginValidator();
private TenantProfileService tenantProfileService;
public String getLoginId() {
return loginId;
public void setLoginId(String _loginId) {
loginId = _loginId;
public String getPassword() {
return password;
public void setPassword(String _password) {
password = _password;
public LoginService getLoginService() {
return loginService;
public void setLoginService(LoginService loginService) {
this.loginService = loginService;
*public String login() {*
* String authenticationStatus = GenesisConstants.RESULT_FAIL;*
* appLogger.enterMethod(this, "login", loginId);*
* if (loginValidator.validateData(this)) {*
* try {*
* long profileId = loginService.authenticateUser(loginId,*
* password);*
* TenantProfileData tenantProfileData = retrieveTenantProfile(profileId);*
* if (tenantProfileData == null || !tenantProfileData.getStatus().equalsIgnoreCase(*
* GenesisConstants.TENANT_STATUS_ACTIVE))*
* throw new LoginException(*
* "Tenant profile Not Active for the user.");*
* authenticationStatus = GenesisConstants.RESULT_SUCCESS;*
* } catch (LoginException le) {*
* appLogger.error("Error in User Authentication", le.getMessage());*
loginValidator.addErrorMessage(null, le.getMessage());
* authenticationStatus = GenesisConstants.RESULT_FAIL;*
appLogger.exitMethod(this, "login", loginId);
return authenticationStatus;
public TenantProfileData retrieveTenantProfile(long profileId) {
appLogger.enterMethod(this, "viewTenant");
FacesContext facesContext = FacesContext.getCurrentInstance();
Map<String, Object> sessionMap = facesContext.getExternalContext()
.getSessionMap();
appLogger.debug("profileId==", profileId + "");
TenantProfileData tenantProfileData = new TenantProfileData();
try {
appLogger.debug("invoking TenantProfileService.getTenantById");
tenantProfileData = tenantProfileService.getTenantById(profileId);
appLogger
.debug("successfully completed TenantProfileService.getTenantById");
} catch (TenantProfileServiceException te) {
appLogger.debug("exception in TenantProfileService.getTenantById");
throw new DataException(te.getMessage());
sessionMap.put("tenantProfileData", tenantProfileData);
appLogger.exitMethod(this, "viewTenant");
return tenantProfileData;
public TenantProfileService getTenantProfileService() {
return tenantProfileService;
public void setTenantProfileService(
TenantProfileService tenantProfileService) {
this.tenantProfileService = tenantProfileService;
PLEASE HELP
THANKS -
How to maintain session-expiration details..?
Where i have to include session-expiration time in ATG (i.e how to fire an session-expiration event) ..
Thanks in Advance,
Vishnu & Nithin Kayithiyou might want to check this link.
http://atgkid.blogspot.com/2011/11/atg-session-management.html -
How to invalidate session in JSP?
I am new to web development.
I have tried to invalidate a session with session.invalidate() but this does not seem to have invalidated the session. Any Help Please??please elaborate on your problem,
session.invalidate(false) should work..false means, if there is a session, invalidate, if not..DONT create one... -
How to maintain session state in APEX
Hi friends,
I have a form with two page items and two buttons( submit ----->submits the page and inserts a record, cancel ------>redirects to other page)
*)p1_A
*)p2_B
If i entered a value in the page item p1_A and p2_A, and after that without pressing "Submit" Button im pressing "Cancel" button means it is redirecting to the other page and again if i came back to my form page means, the values that i entered in the page item
*)p1_A and p2_B is disappearing.
Is is possible to maintain a values entered in the page item (p1_A and p1_B) without submitting it and navigating to some other page.
Brgds,
MiniHi Peter,
Thanks for the reply.
Generally i have two page 1 and page 2
page 1 contains 2 page items
<li> P1_A
<li> P1_B
in the page 1 itself i have a list called po order.
If i clicked that list po order means, it is navigating to the page 2. My page 2 also contains below two items and a button BACK
<li> P2_A
<li> P2_B
After i entered the values in P2_A, P2_B and if i press the back button means, it is redirecting to the page 1. Again if i click the list po order means it is navigating to the page 2 but the values that i entered in P2_A, P2_B is disappeared.
Whether it is possible to maintain the values that i entered in the page items P2_A, P2_B soon after redirection. Mainly im not submitting page 2, just redirecting back to it.
settings to do that at the Button settingsAnd u said of doing that settings in the button that i have in page 2.
yes i found the option set items with the values
set item: P2_A with values: &P2_A.
But it didnt worked. Am i wrong.
Kindly help me with this issue peter.
Brgds,
Mini -
Hello,
Does anyone know how to maintain session and application variables through server restarts? I want to be able to shutdown and startup my Tomcat server without having the users lose their session and application variables (and consequently, their data and login state).
Any ideas?
Thanks!
-DavidI dont think its possbile since stopping and restarting gets new sessions. Only way that I would know would be to use cookies.
But then again i dont like the idea of saving passwords in cookies -
Maintain session in Multiple soap calls
Hi Experts,
We have an requirement which runs 2 synchronous calls.
1st synchronous cal is for validating user credentials and
2nd synchronous call (for successful log in) for uploading data in R/3 system.
The main task is to maintain session(ex: time 15 mins) .
1st synchronous call looks like Mobile Application (soap sender)<--->PI<----->(Soap receiver)Active Directory.
2nd synchronous call looks like Mobile Application (Soap sender)<--->PI<----->(Proxy)R/3 system.
can you pls let me know how can I achieve this requirement and
how to maintain session ID, session (is it in PI or in third party) and from where to maintain session.
Thanks in Adv..I am calling multiple web service apis from my bpel process on the same link. The Web services are written such that I always have to call a "login" api first which creates a context that's maintained throughout the session. Thus subsequent ws calls have to be made in the same session because all the other web service apis require the context to be present.
You can think of this as a stateful SessionBean (sort of).
The question is does bpel support this? -
How to use session object in jsp
hi all
marry christmas
can anyone plz tell me how to use session obect in jsp
rachna
Message was edited by:
rachna_arora82hi rachna,
JSP has a default(implicit) session object...... use the getSession(true) method on the session object and then going u can either get or set attributes depending on the requirement
That was in general and now with the issue u have got..... what u can do is that the u can create session for every user who logs in and when he/she tries to login again then u can probably check for the existing session object in the JSP and perform the logic as required..... any clarifications plzzzzzzz let me know
Thanks n Regards
Naveen M
Message was edited by:
Novice_inJAVA
Message was edited by:
Novice_inJAVA -
How to Handle user Session in JSP
Help me,
How to handle user session in JSP.......Prakash_Pune wrote:
tell me some Debugging tech. so i can overcome from my problem.....Do you use an IDE? Any IDE ships with a decent debugger where in you can just execute the code step by step, explore the current variable values and check what exactly is happening. For example Eclipse or IntelliJ. If you don´t use an IDE, then just place some System.out.println() or Logger.debug() statements at strategic locations printing the variables of relevance so that you can track in logs what exactly is happening.
or tell any other way to find is my page is thread safe or not...Just write correct code and narrow the scope of the variables as much as possible. If you for example assigned the user object to a static variable or as a servlet´s instance variable, then exactly the same user object would be used everywhere in the application. That kind of logical things. -
How to get session.maintain property on server side?
Is there a way to trap javax.xml.rpc.session.maintain property on the server side in JAX-RPC compliant web service implementation? I would like to know if the client has enabled session.maintain property to true (which false by default). If not, can I specify the web service to be of "Application" or "Session" scope during deployment time? It used to be the case for Apache SOAP processor. I do not see any mention of that in the JAX-RPC spec.
Thanks for any pointers.
-Anirban.When I first started to work with JAXRPC I had questions about how web services maintained session across multiple calls and also if it was
possible to maintain session across multiple web services. I downloaded
the JAXRPC runtime implementation source code and tell you what I found.
There is a HttpClientTransport class that handles the actual HttpConnection to the server. It checks to see if maintain session is
set to true or false. If it is set to true it appends the JSESSIONID to the header variables of the request.
The very first call gets a response back with header variable
Set-Cookie: JSESSIONID=blahblahblah
The HttpClientTransport looks for it and if it finds it takes the cookie and stores it somewhere. Every call after that will check to see if session maintain is true or false. If true, it will send
the header:
Cookie: JSESSIONID=blahblahblah
Hope that helps.
Mike -
How webcenter maintain the session .
Hi All,
Can anybody explain me how webcenter maintain its session .
As of my understanding if we perform any action on webcenter component it goes through some service call .
Once this service call is madle idle icon keep moving that says your session is refreshed now .
Please can u let me know which function and how it is called to idle timer to refresh (revolve).
Its very important for me since i want to call this function from my template to refresh the session since i am not using standard portlet connection through wsrp .
With Regards ,
Arun.Well, you're not wrong, but things could be clarified...
Check out + session invalidation... I presume you mean you explicitly invalidate it, yes? The session will timeout eventually anyway (unless you make it have no timeout).
Anyway, to you actual question. The container manages them, to an extent. It handles sessions automatically for you thru session cookies with the session ID. But if the user has cookies disabled, then that'll muck things up. Generally, it's good practice to always use URL rewriting on your links to make sure that's not a problem.
Maybe you are looking for
-
Help! My Mac book pro is 1 year old. I just updated my software yesterday now upon starting up, the computer will not move past the start up apple screen. Any suggestions?
-
Duplicate target database for standby failing ...
hi, below is the message reported at the end of rman session log: channel ORA_AUX_DISK_1: restore complete, elapsed time: 01:09:50 failover to previous backup RMAN-00571: =========================================================== RMAN-00569: =======
-
I have a Fujifilm IS100. I would like to convert RAW to DNG and TIFF to DNG. Could someone advise me what software I would need to do this. I presently have have Lightroom 3.6 and Elements 4 (I am sure you can see I am on a really tight budget), when
-
Color Management / Error Message
In Adobe Bridge all pictures show a strong and un-natural blue tone. Trying to use the colormanagement to applicate my (calibrated) monitor profile, I get the error report: "Suite color management is not activated. Suite Color management is only poss
-
On my machine (FW 800), 10.4.7 caused: machine to slow perceptably after wake from sleep. Activity Monitor tells me kernel_task is consuming hundreds of times it's normal CPU cycles. I installed a FRESH 10.4. Imported my files and folders. Upgraded a