Home Answers Viewqa JSP-Servlet To store value in session & display it

 
 


Suman Rakshit
To store value in session & display it
0 Answer(s)      a year and 4 months ago
Posted in : JSP-Servlet

Hello..I m trying to run the following code which will store the session of a book selected on click of the button.But first it was showing NullPointerException and then blank page..Please Help me in this.. This is the JSP Page

<html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Book Catalog1</title>
        </head>
        <body>
            <form action="/Books/addtocart" target="add">
               <!-- <input type="checkbox" name="book1cat" value="JSP" />JSP
             <input type="checkbox" name="book1cat" value="C" />C
              <input type="checkbox" name="book1cat" value="Java" />Java
               <input type="checkbox" name="book1cat" value="Servlet" />Servlet<br/>-->
               <b>Jsp</b><input type="submit" value="Add JSP To Cart" name="ADD" /><br/>
                <b>Java</b><input type="submit" value="Add Java To Cart" name="ADDJSp" /><br/>

            </form>

        </body>
    </html>

This is the servlet page where i m storing the value(this code is for selecting the first book only):

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class addtocart extends HttpServlet {



    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();

        HttpSession hs=request.getSession(true);


       if(hs.isNew()){
            hs.setAttribute("ADD", new int[] {0});
        }
        int[] ADD=(int[])hs.getAttribute("ADD");
        try {


        if((String)request.getParameter("ADD")!=null){
            ADD[0]++;
              out.print("Brought a JSP book.You now have "+ADD[0]+ "JSP book");
        }

             out.print("<HTML><HEAD><TITLE>Shopping Cart</TITLE></HEAD><BODY>");


     out.print("<HR><A HREF='/Books/Book1.jsp'>Go to Main</a>");
 } finally {            
            out.close();
        }
    }
View Answers









Related Pages:
To store value in session & display it
To store value in session & display it  Hello..I m trying to run the following code which will store the session of a book selected on click...="add"> <!-- <input type="checkbox" name="book1cat" value
Display session value Using Servlet
Display session value Using Servlet     ... will be invalidated automatically. A negative value indicates that the session...: In case of first time accessing of servlet the following session value
session
session   explain sessioln tracking in jsp and display program
Session
Session   hii, What Is a Session?   hello, Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor
Session Object
. The session object is used by the developers to store and retrieve user's..., java.lang.Object value)- for storing the an object in session. getAttribute...Session Object  Why do we require Session Object?  Hello
Session
Session  What Is a Session?   Hi friends, A session... subsequent HTTP requests. There is only one session object available to your PHP scripts at any time. Data saved to the session by a script can be retrieved
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
;A servlet session is created and stored on the server side. The servlet container keeps.... To the maintain the session, Web clients must pass back a valid session identifier as a cookie header value or dynamically generated URL parameter
Get session value in javascript
Get session value in javascript   How to iterate session value onebyone in JavaScript
Problem to display checkbox item
don't know exactly, but can we store it in session and in collection so that we...Problem to display checkbox item  Hi, Following is my code: <...;td> <input type="checkbox" name="check" value=<
session tracking - Ajax
session tracking  explain session tracking with example?  Hi friend, Session tracking is a mechanism that servlets use to maintain state... solutions to this problem 1.Cookies : You can use HTTP cookies to store
JFreeChart- Display coordinate value .
JFreeChart- Display coordinate value .  How to Mark Coordinte value on top of the bar
store value in checkbox from gridview
store value in checkbox from gridview  Please check the error...; <input type="submit" value=" DELETE "/>&nbsp;&nbsp..." name="chbox<%=no%>" value="<%= rst.getString("name") %>" ></td>
Session tracking basics
; Session tracking Example: </description> <display-name>Session tracking Example</display-name> <context-param> <param... Session Tracking Basics      
Stateless Session Bean Example
-name>Stateless Session Bean Example</display-name>... Stateless Session Bean Example       In this part of Enterprise Session Beans, you will learn how
how to store jtable value in multidimensional array?
how to store jtable value in multidimensional array?   i want to store the value of jtable in multidimensional array,with type double. how to store jtable value in multidimensional array
how to store jtable value in multidimensional array?
how to store jtable value in multidimensional array?   i want to store the value of jtable in multidimensional array,with type double. how to store jtable value in multidimensional array
store dynamic generated textbox value into database
store dynamic generated textbox value into database  sir, how do i store dynamically generated textbox value into the database thanks in advance
Display of value in Tabel cell
Display of value in Tabel cell  I have added a custom field..., Object value , boolean isSelected, int row, int column){ JPanel...(editor.getTableCellEditorComponent(table, value, isSelected, row, column)); panel.add
How many cookie object we can store in a session? is there any limit?
How many cookie object we can store in a session? is there any limit?  How many cookie object we can store in a session? is there any limit
get a session object - JSP-Servlet
get a session object  how to do in a table when i click on a radio button i should get the id value which is in the same row and store it in the session this is in jsp when in the servlet if i call a get session i have to get
store html value in the sqllite 3 php
store html value in the sqllite 3 php  i have a php script that will parse html page content link and view but i need to know how to store... tell db to store html content from $articles $result = $db->query('SELECT bar
Code to store SubCombo box value - Development process
Code to store SubCombo box value   Hi ,In the following code i want to store SubCombo box name instead of value for Department Field. Add Data var arr = new Array(); arr["Select"] = new Array("-select-"); arr["Dkn
. Display JavaScript dropdown selected value
you select any value from list, alert will display that. In var.... Display JavaScript dropdown selected value  How to get the selected value from dropdown box? I am using javascript.   <html> <
Store combo box value - Development process
Store combo box value  Hi , this is my code. Here wen i click submit button combo values are stored like 1,2,3... but i want to store value . plz send me code. while validating a form, i have entered data in first field
session value not get in many jsp page.
session value not get in many jsp page.  I am using servlet to set session by following code :- HttpSession session=request.getSession(false...,response); and get session value on jsp page by follwing:- String user=(String
Page Directive attribute - session
uses HTTP sessions. The true  value of session attribute indicates that the JSP page has permission to access existing session and false value... value of session attribute is True. Syntax : <%@ page session="true
JSF SESSION - Java Server Faces Questions
JSF SESSION  i am facing problem to store and retrive textbox values in session variable in jsf, i want to store textbox value in bean as well as in session variable but when submitting the form it showing null.i have written
Writing Calculator Stateless Session Bean
; <display-name>Shopping Cart Session Bean</display-name>...; <display-name>EJB Test Session Bean</display-name>... Bean</description> <display-name>EJB Calculator Session
Maximum length of Session ( $_SESSION ) in PHP.
Maximum length of Session ( $_SESSION ) in PHP.  sir, i want to know that how much limit of storing data into session in php. i mean can i store full product descriptions into session. Thank u
Deploying and testing Stateless Session Bean
Deploying and testing Stateless Session Bean... Session Bean developed in the last section. We will use ant build tool to build...;property name="dirs.base" value="${basedir}"/> <property name
JSTL: Set Session Attribute
which we want to set in the attribute value and store it in the attribute var...; The value which we have set in the session is <b><c:out value...JSTL: Set Session Attribute     
Session ID
or with people acquiring other users' data. The session ID value should be managed...Session ID  How can I change the session ID of the page?   The servlet session represents a relationship between the servlet container
Session Timeout
Session Timeout  Hi, we are using JBoss 4.0.2 I have edited... increased the application timeout value to 120(i.e 2 hours), and reastarted the server. But, the session timeout is not happening for 120 mins
JSP Implicit object "session"
the variables and the value remains for the user?s session. The concept... of the current session is returned. The value returned by this method is an enumeration.... isNew():   The isNew() method of session object returns a true value
I want to store the value of local variable into Global variable
I want to store the value of local variable into Global variable    <%=cnt%>=x; is it a valid Statement
store input and display previous input as well current input. in jsp
store input and display previous input as well current input. in jsp  Hi Friend, In this JSP program i want display the previous input as well... am trying to take new input it replaces old one. i want to store and display
PHP Session
PHP Session        A PHP session variable is used to store the information about a user... duration etc. Session does not store the data permanently, whenever the user
developing a Session Bean and a Servlet and deploy the web application on JBoss 3.0
;test_MyTestSession"> <display-name>My Test Session Bean<...;/servlet-name> <display-name>Simple Session Servlet</display... Writing Stateless Session Bean and Calling through Servlet
developing a Session Bean and a Servlet and deploy the web application on JBoss 3.0
;session id="test_MyTestSession"> <display-name>My Test Session...="Calculator"> <display-name>Calculator Session Bean</display... a Calculator Stateless Session Bean and call it through JSP file  and deploy
The 'session' Attribute of JSP page Directive
The 'session' Attribute of JSP page Directive This section, illustrate about 'session' attribute of page directive with help of a example. It specifies if the generated servlet can access the session
How to Store Float Value into Access Database - Java Beginners
How to Store Float Value into Access Database  Hello sir,I want to Store Student Marks Percentage into Access Database in Float Value how i can Store.... To store the double value in Access database, you need to set the datatype
How to store two integer value in a separate file and retrieve those values
How to store two integer value in a separate file and retrieve those values  I need to save two values so i can use those values later i came up... can i write and update value in that file
PHP Session
Session: A session variable is used to store some useful data and that data is accessible from every page. In PHP $_SESSION is a pre-defined variable... by allowing us to store useful data on the server. Data stored in session
How many ways can we get the value of current session id?
How many ways can we get the value of current session id?  How many ways can we get the value of current session id
Writing Deployment Descriptor of Stateless Session Bean
; <application> <display-name>Stateless Session...;display-name>Shopping Cart Session Bean</display-name>...;/description> <display-name>EJB Test Session Bean</display-name>
java script display value - Java Beginners
java script display value  my code is below: my problem is: the value 'firstname' is not showed with getparameter in .jsp file? (when click submit button in form) Main file: Name: file java
Code to store sub combo box value - Development process
Code to store sub combo box value  Hi Deepak, In the following code i want to store subcombo box value instead of number. Already "Dkn/Tmz" ,"kungumam... etc are storing but i want to store "Circulation,marketing
how to display textbox value based on selected option value?
how to display textbox value based on selected option value?  Hi,I... on first value I finished above code. ID: xx Name:xx xx is baesd on second and first value. But it is that l can't do that. now, l post my code
Write cookie and session to textfile?
Write cookie and session to textfile?  I want to store all data from user submisstion into a textfile, include session and cookie. Thanks

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.