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

  • SEARCH
  • Home
  • 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 9283597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:40:17+00:00 2026-06-18T18:40:17+00:00

I am developing a web application in JSP. I made this page with JSP,

  • 0

I am developing a web application in JSP. I made this page with JSP, CSS and HTML. There are six buttons. Every button calls a JavaScript method, so the first button is a call of the par() method.

  <html>
<head>
<title>Welcome   d To Student University</title>
<link rel="stylesheet" type="text/css" href="../css/stlogin.css">
<link rel="stylesheet" type="text/css" href="../css/background.css">
<link rel="stylesheet" type="text/css" href="../css/back.css">
<script src="StInfo.jsp">
</script>

</head>
<body>
<div class=main>
    <div class=blank></div>
    <div class=welcome><h1 class=welcome><center>Welcome Student</center></h1>
    <div class=logout><a href='logout.jsp?value=st'>Logout</a></div></div>
</div>
<br>
<div class=menu>
    <div class=leftgap>.
    </div>
    <div class=option>
    <center>
    <button type="button" onclick=par() class="Bt_menu">Check Parsnal Info</button>
    </center>
    </div>
    <div class=option>
    <center>
    <button type="button" onclick=faculty() class="Bt_menu">All Faculty Details</button>
    </center>
    </div>
    <div class=option>
    <center>
    <button type="button" onclick=exam() class="Bt_menu">Next Exams Details</button>
    </center>
    </div>
    <div class=option>
    <center>
    <button type="button" onclick=atten() class="Bt_menu">Attendance Details</button>
    </center>
    </div>
    <div class=option>
    <center>
    <button type="button" onclick=Result() class="Bt_menu">Exam Result Details</button>
    </center>
    </div>
    <div class=option>
    <center>
    <button type="button" onclick=Notices() class="Bt_menu">College Notices / Details</button>
    </center>
    </div>
</div>
<p id=Table></p>
</body>
</html>

in this page i used this script tage as :-

<script src="StInfo.jsp">
</script>

now i show u my StInfo.jsp file there are the java script method .

<%@page import="data.*;" %>
<%
ServletConfig con=getServletConfig();
ServletContext ctx=con.getServletContext();
DataRet d;
%>
function par()
{
try
{
// i sat ctx.setAttribute("id") is 1 already in my last page . so the output will be 1 of it .
<%DataRet.setAtt(""+ctx.getAttribute("id"),"stlogin");%>
var id=<%=ctx.getAttribute("id")%>                // if i did that than the value 1 store in id .
var id=<%=DataRet.get(2)%>                        // but when i did that nething happen and code didn't work .
}catch(err)
{
txt="There was an error on this page.\n\n";
txt+="Error description: " + err.message + "\n\n";
txt+="Click OK to continue.\n\n";
alert(txt);
}
//alert("id");
document.getElementById("Table").innerHTML="<center><table border='10'><th>College Id</th> <th>Name</th><th>Father Name</th><th>Department</th><th>Year</th><th>Semester</th><th>Ph. No.</th><th>Address</th>\
<tr>\
<td>"+id+"</td>\
<td>"+id+"</td>\
<td>"+id+"</td>\
<td>"+id+"</td>\
<td>"+id+"</td>\
<td>"+id+"</td>\
<td>"+id+"</td>\
<td>"+id+"</td>\
</tr></table><center>";


}

and here is my DataRet File —

   package data;
import java.sql.*;
import connection.connection;
public class DataRet
{
static Connection c;
static ResultSet re;
static Statement s;
static String id;
static
{
    try
    {
        c=connection.getConnect();
        System.out.println(c);
        s = c.createStatement();
        System.out.println("Statement Object Created = "+s);
    }catch(Exception e){System.out.println(e);}
}
public static void setAtt(String table)
{
    try{
    re=s.executeQuery("select * from "+table);
    }catch(Exception e){}
}
public static void setAtt(String att,String table)
{
    System.out.println("Table Sated");
    id=att;
    int i=0;
    try
    {
        re=s.executeQuery("select * from "+table);

        while(re.next() && re.getString(3).equals(att))
        {
            i++;
            break;
        }
    System.out.println("curser on "+i);
    }catch(Exception e){System.out.println(e);}
    }
    public static void change()
    {
        try{
            re.next();
        }catch(Exception e){}
    }
    public static String get(int val)
    {
        System.out.println("value geted of "+val);
        try{
            String o=re.getString(val);
            //o=string.valueOf(o);
            System.out.println(o);
            return o;
        }catch(Exception e){ System.out.println("Problum in Geting Value"+e);}
        System.out.println("return null");
        return null;
    }
}

Now the question is that when i call a method *<%=ctx.getAttribute(“id”)%> * in stInfo.jsp then this method print 1 in very coloum . and when i call
<%=DataRet.get(2)%> method then file didn’t work ….

  • 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-18T18:40:19+00:00Added an answer on June 18, 2026 at 6:40 pm

    The storing of data from a JSP scriptlet should be pretty straight forward just like you have it.

    var id=<%=ctx.getAttribute("id")%>
    

    Although I would recommend you to be careful with the returning data, if it isn’t a number for sure, then you must put it between quotes just to be sure the JS doesn’t break. For example:

    if <%=DataRet.get(2)%> returns a string "TEST" then the resulting JS would look like:

    var id=TEST
    

    And that would just simply break because there is no variable named TEST. You need to enclose it in double or single quotes like:

    var id="<%=DataRet.get(2)%>";
    

    Also you have to keep in mind the semicolons at the end of every line, and escape any possible chars that can break the JS code. Remember, the JS code has not been executed yet after the JSP has compiled, so it is like if you wrote that JS code manually.

    If this code is not working start by checking what <%=DataRet.get(2)%> is returning, and also if there are any JS errors.

    Hope it helps.

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

Sidebar

Related Questions

I am developing a small email web application in JSP/Javascript/html. It has a logout
I am currently developing a jsp web application that maintains two clients of two
I'm developing web-application, in this I want to add all months values on the
so this is question for 1mln$. First of all, I'm developing web application in
I am developing a web application which follows the principle of responsivness. Every information
I am developing a web application using JSP & Servlet.(IDE: Eclipse, Container: Tomcat7.0) To
I am developing web application using JSP and Servlet (IDE: Eclipse, Container: Tomcat7.0, DB:
I developing a web application using JSP & Servlet (IDE: Eclipse, Database: Oracle10). I
I am developing a web application using JSP & Servlet (IDE: Eclipse, Database: Oracle10).
I am developing a web application using JSP & Servlet (IDE: Eclipse, Database: Oracle10).

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.