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 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 Tutorials/Questions & Answers:
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     ... the session will be invalidated automatically. A negative value indicates... the following session value will be displayed ADS_TO_REPLACE_3 In case of preexist
Advertisements
Get session value in javascript
Get session value in javascript   How to iterate session value onebyone in JavaScript
JFreeChart- Display coordinate value .
JFreeChart- Display coordinate value .  How to Mark Coordinte value on top of the bar
ModuleNotFoundError: No module named 'display-session'
ModuleNotFoundError: No module named 'display-session'  Hi, My... named 'display-session' How to remove the ModuleNotFoundError: No module named 'display-session' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'display-session'
ModuleNotFoundError: No module named 'display-session'  Hi, My... named 'display-session' How to remove the ModuleNotFoundError: No module named 'display-session' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'display-session'
ModuleNotFoundError: No module named 'display-session'  Hi, My... named 'display-session' How to remove the ModuleNotFoundError: No module named 'display-session' error? Thanks   Hi, In your python
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
ModuleNotFoundError: No module named 'odoo12-addon-muk-session-store'
ModuleNotFoundError: No module named 'odoo12-addon-muk-session-store' ...: No module named 'odoo12-addon-muk-session-store' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-muk-session-store' error
ModuleNotFoundError: No module named 'odoo12-addon-muk-session-store'
ModuleNotFoundError: No module named 'odoo12-addon-muk-session-store' ...: No module named 'odoo12-addon-muk-session-store' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-muk-session-store' error
ModuleNotFoundError: No module named 'scylla_django_session_store'
ModuleNotFoundError: No module named 'scylla_django_session_store'  ...: No module named 'scylla_django_session_store' How to remove the ModuleNotFoundError: No module named 'scylla_django_session_store' error? Thanks
Version of com.aerospike>aerospike-session-store dependency
List of Version of com.aerospike>aerospike-session-store dependency
Version of com.nimbusds>oidc-session-store dependency
List of Version of com.nimbusds>oidc-session-store dependency
. 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> <
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
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>
Maven Dependency aerospike-session-store >> 0.9
You should include the dependency code given in this page to add Maven Dependency of com.aerospike >> aerospike-session-store version0.9 in your project
Maven Dependency aerospike-session-store >> 0.9.1
You should include the dependency code given in this page to add Maven Dependency of com.aerospike >> aerospike-session-store version0.9.1 in your project
Maven Dependency aerospike-session-store >> 1.1
You should include the dependency code given in this page to add Maven Dependency of com.aerospike >> aerospike-session-store version1.1 in your project
Maven Dependency aerospike-session-store >> 1.2
You should include the dependency code given in this page to add Maven Dependency of com.aerospike >> aerospike-session-store version1.2 in your project
Maven Dependency oidc-session-store >> 5.3
You should include the dependency code given in this page to add Maven Dependency of com.nimbusds >> oidc-session-store version5.3 in your project
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:- (adsbygoogle
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
Maven Repository/Dependency: com.aerospike | aerospike-session-store
Maven Repository/Dependency of Group ID com.aerospike and Artifact ID aerospike-session-store. Latest version of com.aerospike:aerospike-session-store dependencies. # Version Release Date
com.nimbusds - oidc-session-store version 4.12.2 Maven dependency. How to use oidc-session-store version 4.12.2 in pom.xml?
com.nimbusds  - Version 4.12.2 of oidc-session-store Maven dependency? How to use  com.nimbusds  - Version 4.12.2 of oidc-session-store in pom.xml? How to use oidc-session-store version 4.12.2 in pom.xml? Learn to use
com.nimbusds - oidc-session-store version 4.0.5 Maven dependency. How to use oidc-session-store version 4.0.5 in pom.xml?
com.nimbusds  - Version 4.0.5 of oidc-session-store Maven dependency? How to use  com.nimbusds  - Version 4.0.5 of oidc-session-store in pom.xml? How to use oidc-session-store version 4.0.5 in pom.xml? Learn to use
com.nimbusds - oidc-session-store version 4.0.3 Maven dependency. How to use oidc-session-store version 4.0.3 in pom.xml?
com.nimbusds  - Version 4.0.3 of oidc-session-store Maven dependency? How to use  com.nimbusds  - Version 4.0.3 of oidc-session-store in pom.xml? How to use oidc-session-store version 4.0.3 in pom.xml? Learn to use
com.nimbusds - oidc-session-store version 5.1 Maven dependency. How to use oidc-session-store version 5.1 in pom.xml?
com.nimbusds  - Version 5.1 of oidc-session-store Maven dependency? How to use  com.nimbusds  - Version 5.1 of oidc-session-store in pom.xml? How to use oidc-session-store version 5.1 in pom.xml? Learn to use
how to display the value of termcell name in label
how to display the value of termcell name in label  want to display the tercell name in label report of pending apllication of termcellname code...="display"%> <%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html"%> <
Maven Repository/Dependency: com.nimbusds | oidc-session-store
Maven Repository/Dependency of Group ID com.nimbusds and Artifact ID oidc-session-store. Latest version of com.nimbusds:oidc-session-store dependencies. # Version Release Date 1
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
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
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
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
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
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
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
session
session   explain sessioln tracking in jsp and display program
how to use dropdown list in JSP and display value in same page
how to use dropdown list in JSP and display value in same page  I... one option the value must get displayed below it in the same page as: Value selected = B Now if choose another option, new message should be printed
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 display each arraylist value on new page in jsp
how to display each arraylist value on new page in jsp  hi!!!! i want to display each arraylist value on new page in jsp????? and also want to access the arraylist values using next button..... any help would be appreciated
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
Maven dependency for com.aerospike - aerospike-session-store version 0.9 is released. Learn to use aerospike-session-store version 0.9 in Maven based Java projects
-session-store released The developers of   com.aerospike - aerospike-session-store project have released the latest version of this library on 27 Jul 2015, the released version of  com.aerospike - aerospike-session-store
Maven dependency for com.aerospike - aerospike-session-store version 0.9.1 is released. Learn to use aerospike-session-store version 0.9.1 in Maven based Java projects
-session-store released The developers of   com.aerospike - aerospike-session-store project have released the latest version of this library on 27 Jul 2015, the released version of  com.aerospike - aerospike-session-store
Maven dependency for com.aerospike - aerospike-session-store version 1.1 is released. Learn to use aerospike-session-store version 1.1 in Maven based Java projects
-session-store released The developers of   com.aerospike - aerospike-session-store project have released the latest version of this library on 16 Oct 2015, the released version of  com.aerospike - aerospike-session-store
Maven dependency for com.aerospike - aerospike-session-store version 1.2 is released. Learn to use aerospike-session-store version 1.2 in Maven based Java projects
-session-store released The developers of   com.aerospike - aerospike-session-store project have released the latest version of this library on 14 Dec 2015, the released version of  com.aerospike - aerospike-session-store
Maven dependency for com.nimbusds - oidc-session-store version 5.0 is released. Learn to use oidc-session-store version 5.0 in Maven based Java projects
-store released The developers of   com.nimbusds - oidc-session-store..., the released version of  com.nimbusds - oidc-session-store library is 5.0. Developer can use this version ( com.nimbusds - oidc-session-store version 5.0

Ads