问题描述:

I am developing a web application. I have get the value from the data base using jsp and displayed to the user. On certain action from the user, i want to load the another page which will require same values which are fetched from the database.

For this I have created json object of this data in page1.jsp and passed to the another page2.jsp.

Now I want to retrieve that data. I have tried with gunction getString() functions, but it gives null value.

my first page is which sends the json data

$.ajax({

type : "POST",

url: "./ProfileUser.jsp", // This not redirecting.

data: "jsonData=" + JSON.stringify(jsonobj),

dataType: "json"

});

$(location).attr('href',url); //This is redirecting, If I removed this then another page is NOT loading

and the jsp code where I am retrieving this data

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@page import="com.google.gson.JsonObject" %>

<%@page import="org.codehaus.jettison.json.JSONObject"%>

<%

String jsonData = request.getParameter("jsonData");

JSONObject j =new JSONObject(jsonData);

String mobile = j.getAttribute("mobile"); //error occures here

%>

And i get error

type Exception report

message An exception occurred processing JSP page /ProfileUser.jsp at line 15

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /ProfileUser.jsp at line 15

12: <%

13: String jsonData = request.getParameter("jsonData");

14: //JONObject userinfo = (JSONObject) new JSONTokener(jsonData).nextValue();

15: JSONObject j =new JSONObject(jsonData);

16: String mobile = j.getString("mobile");

17: %>

18: <!DOCTYPE html>

Stacktrace:

org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)

javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

root cause

java.lang.NullPointerException

org.codehaus.jettison.json.JSONTokener.more(JSONTokener.java:89)

org.codehaus.jettison.json.JSONTokener.next(JSONTokener.java:99)

org.codehaus.jettison.json.JSONTokener.nextClean(JSONTokener.java:153)

org.codehaus.jettison.json.JSONObject.<init>(JSONObject.java:168)

org.codehaus.jettison.json.JSONObject.<init>(JSONObject.java:266)

org.apache.jsp.ProfileUser_jsp._jspService(ProfileUser_jsp.java:75)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)

javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)

javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

How can get this data in jsp?

Thank you.

相关阅读:
Top