Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8286461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:46:43+00:00 2026-06-08T11:46:43+00:00

i have a JSP file in which i have declared a method which return

  • 0

i have a JSP file in which i have declared a method which return a json . now i want to get this json in a js file using ajax . but when i use ajax call it returns whole jsp page instead of json data
here is my jsp

<%-- 
    Document   : index
    Created on : Jul 26, 2012, 3:49:33 PM
    Author     : tagit
--%>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="my.mychartData"%>
<%@page import="my.mychartInfo"%>
<%@page import="my.mychart"%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
         <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
         <script type="text/javascript" language="javascript">
         </script>
    </head>
    <body>
 <%!
 Object showchart()
 {
 mychartInfo c1 =new mychartInfo();
 mychartInfo c2=new mychartInfo();
 mychartInfo c3=new mychartInfo();
 mychartInfo c4=new mychartInfo();
 mychartInfo c5=new mychartInfo();
 mychartInfo c6=new mychartInfo();
mychartData c7=new mychartData();

c1.setColor("pink");
c1.setDataDes("Gas data");
c1.setDataVal("20");
c1.setName("Gas");
c2.setColor("green");
c2.setDataDes("cash data");
c2.setDataVal("30");
c2.setName("Cash");
c3.setColor("blue");
c3.setDataDes("Resturent data");
c3.setDataVal("38");
c3.setName("Resturent");
c4.setColor("blue");
c4.setDataDes("boat data");
c4.setDataVal("60");
c4.setName("Boat");
c5.setColor("black");
c5.setDataDes("Movies data");
c5.setDataVal("40");
c5.setName("Movies");
c6.setColor("yello");
c6.setDataDes("Shopping data");
c6.setDataVal("50");
c6.setName("Shopping");
c7.setDonut("30");
c7.setFont("afdafafafafaf");
c7.setGradientPos("leftsdgd");
mychart chart1=new mychart();

Object obj =chart1.addChart(c1, c2, c3, c4, c5, c6, c7);
return obj ;
 }
%>

     <%
     out.println( showchart());
     %>
     %>
    </body>
</html>

And this is my ajax function

    $.ajax({
        type: "get"
       ,dataType: "json"
       , url: "http://localhost:8080/Webcharts/index.jsp;"
       ,success: function(json){
       alert("here"+json);

}
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:46:44+00:00Added an answer on June 8, 2026 at 11:46 am

    Don’t write any HTML code on the JSP. Set the contentType.

    You need to serialize the object to JSON. It won’t do it automatically.

    IMHO its better done with a servlet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSP file which creates an Excel document. I want to dynamically
I want to ask some questions about the JSP and JSON file. I have
I have a form in a jsp file, which I have used to get
I get the strangest thing going on... I have a JSP file which read
I have a config.properties file which my JSP page uses to get configurations from.
I have a very simple JSP file, which more or less displays a get
I have these in a jsp file. But these values are not updated in
I have hard-coded data into a .jsp file. What I want to do is
I have the following in jsp: <form action=/ucReady2/uploadservlet method=post enctype=multipart/form-data> <label for=filename_1>File: </label> <input
In a web project using jsp, I have following requirement Upload a file (say

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.