How to implement session variables
Hi,
I have a servlet which gets parameter from a jsp page(x). it is stored in a variable in servlet as shown below. the servlet response is another jsp page(y). I should put the value of amp_num in the Jsp page (y).
How should i do it? I'm trying using session.getAttribute
SERVLET:
-------------------
HttpSession session = request.getSession(false);
String amp_number = request.getParameter("amp1").toString();
int amp_num = Integer.parseInt(amp_number);
session.setAttribute("xyz",lamp_num);
JSP Page(y):
---------------
<input type="text" name="xyz" value="<%session.getAttribute(xyz); %>" size="20">
I dont need to put in a textfield, its ok if i print it. Do I need to add any path like (@servlet) because how the jsp know from which servlet i'm calling the variable xyz. please help me.
Thanks,
View Answers
June 10, 2010 at 11:33 AM
Hi Friend,
Try the following code:
1)no.jsp:
<form name="form" method="post" action="../ServletExample" >
Enter no:<input type="text" name="amp1"><input type="submit" value="submit">
</form>
2)ServletExample.java:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ServletExample extends HttpServlet{
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
HttpSession session = request.getSession(false);
String amp_number = request.getParameter("amp1").toString();
int amp_num = Integer.parseInt(amp_number);
session.setAttribute("xyz",amp_num);
getServletConfig().getServletContext().getRequestDispatcher("/modified/action.jsp").forward(request, response);
}
}
3)action.jsp:
<%=session.getAttribute("xyz")%>
It will be helpful for you.
Thanks
Related Tutorials/Questions & Answers:
How to implement session variables - JSP-ServletHow to
implement session variables Hi,
I have a servlet which gets..._num in the Jsp page (y).
How should i do it? I'm trying using session.getAttribute
SERVLET:
-------------------
HttpSession
session = request.getSession
Advertisements
session variables server sidesession variables server side
how to hold
session variable for server side..?
request.getSession().setAttribute("wellSelection", uid
set cookieless session variables in jspset cookieless
session variables in jsp I want to know
how to set cookieless
session variables in jsp, because when I run my application multiple...(because these
session variables internally make use of cookie). But I don't want
how to initialise variables in jsp?how to initialise
variables in jsp? 1. what is the problem in the folloing
jsp
<%@ page
import="net.viralpatel.struts.helloworld.form.LoginForm"
%> <%@ page language="java"
contentType="text/html
PHP list all session variables
All
session variables and its values are maintained by the the super global variable $_
SESSION.
$_
SESSION is an associative array. It keeps the
session....
Example of PHP List All
Session Variables
session1.php
<?php
how to implement spring security - Springhow to
implement spring security Hai, iam working on small login application using hibernate on Spring.
I wanted to
implement spring security for my login application. Can any one tell me what is SpringSecurity, and
how VariablesVariables What are the difference between Static
variables, instance
variables and local
variables How to implement FTP using javaHow to
implement FTP using java Hi,
I am a B.tech student and I want to
implement FTP using Java to transfer files and exchange files between FTP client and FTP server.
Could anyone help me for
How to
implement FTP using java
Duplicated Session VariablesDuplicated
Session Variables
... a new
session variable
because it has been created by the JSP container for you... name. Consider we have
declared a
session variable true in jsp page <%@ page
How to implement openId java web based application?How to
implement openId java web based application? In my web application i want to
implement the OpenId just like stackoverflow.com have to login....
Please tell me
how to
implement it in java web application in details
How to destory session in PHPHow to destory
session in PHP Hi,
I have to write a php page for logout. Please tell me what i should write?
ThanksADS_TO_REPLACE_1
Hi,
You can use following code for logout:
<?
session_start();
session sessionsession
how to
implement login-logout
session????
Please visit the following links:
http://www.roseindia.net/quickguide/tomcat/Logout.shtml
http://www.roseindia.net/jsp/javascriptpagerefresh.shtml
http
How to implement a superclass Person? - Java BeginnersHow to
implement a superclass Person?
How to
implement a superclass... of these classes and invokes the toString() method of each of these object.
how to
implement the class..and
how to write the toString method?
please help me...
Session Session how to
session maintaining in servlet with use of hidden fieds
How to implement this superclass Person - Java BeginnersHow to
implement this superclass Person
how to
Implement a superclass Person which it need to Make two classes, Student and Instructor, that inherit...,birthYear=1969],salary=65000.0]'');
}
}
i don't know
how to write a coding
How to implement xml parsing in iphone ? -RVHow to
implement xml parsing in iphone ? -RV In .h file
@interface RootViewController : UITableViewController<NSXMLParserDelegate>{
IBOutlet UITableView *page1;
NSMutableArray *titlearray
PHP Variables Across Files
php
variables across files
We
know
how Variables and Cookies... on the user's computer or
variables can't take
information to every new page. For this reason we use PHP
session variable. PHP
session variable is a method to store
SessionSession
How fined
session is new or old
Session and user would not able to retrieve the information. So,
Session provides that facility to store information on server memory.
2)
Variables are stored in
session...Session
why do we need
session?
actually what stored in a
session Session Session How can we set the inactivity period on a per-
session basis?
We can set the
session time out programmatically by using the method setMaxInactiveInterval() of HttpSession
sessionSession Management in PHP Handling
session in PHP. Can anyone please explain it with the help of an existing example about,
how to handle a
session while a user is logged in PHP
getting variables getting
variables how to get
variables from servlet program to webservice program
Servlet Session in to maintain/manage the
session and the various mechanism to
implement...
How to manage the
Session
Each
session is associates with timeout because HTTP...Servlet
Session
Sometimes it is required to maintain a number of request
sessionsession
how can transfer data of one page to another page using
session in java swing
sessionsession create multiple login on one page in php but
how to use
session sessionsession is there any possibility to call one
session from another
session sessionsession is there any possibility to call one
session from another
session sessionsession
Session management in Java
Environment variablesEnvironment variables
How to set Environment
Variables in JAVA 6 n Tomcat 6
CLASSPATH, JAVA_HOME, PATH, & CATALINA
variables plzzz plzz help me
Implement pushImplement push Hi..
How do you
implement push on a flex applications?
give me answer with example so i clearly understand
Thanks Ans: push
implement on a flex applications using BlazeDS Server