Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Suman Rakshit
To store value in session & display it
0 Answer(s)      2 years and 10 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();
        }
    }

Advertisement
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     ... will be invalidated automatically. A negative value indicates that the session...: In case of first time accessing of servlet the following session value
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
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>
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
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
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
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
. 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> <
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
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
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
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"%> <
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
session
session   explain sessioln tracking in jsp and display program
store
store  i want to store data in (.dat) file format using swing and perform operation on that insertion,deletion and update
store
store  hi i want store some information in my program and use them in other method. what shoud i do
How to access session value using OGNL.
How to access session value using OGNL. In this example, you will see how to access value of session using OGNL expression language in struts2.  ...;sessionOGNL">Access_Value_bean_from_session_OGNL</a> </body> <
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
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
Advertisements
 

 

 

DMCA.com