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 3965656
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:29:39+00:00 2026-05-20T03:29:39+00:00

I need to pass a variable from Admin.java file to index.jsp. I get the

  • 0

I need to pass a variable from Admin.java file to index.jsp. I get the value when I print it in Admin.java. I need to pass that value to another variable which needs to be sent to index.jsp. This new variable gets null value.

The code in Admin.java is

public string static rest;

protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException 
{
    SemanticSearch semsearch = new SemanticSearch(request.getSession());
    semsearch.loadData(REALPATH + RDFDATASOURCEFILE1);

    String res=semsearch.searchForUser(userName, password);
    System.out.println("The value of res been passed is "+res);
    request.setAttribute("rest", res);
    System.out.println("The value of rest is "+rest);
    request.getRequestDispatcher("index.jsp").forward(request, response);

if(res != null)
 {
       request.getSession().setAttribute("access", true);

       System.out.println("Admin:doGet:login:true");
       response.getWriter().write("existsnoadmin");
       return;
}

Output:

The value of res been passed is C Language.
The value of rest is null.

As per the questions asked in stack overflow we need to use forward or redirect when we need to send the value to jsp page. But in my case, I am trying to return value from a function so I do not know whether the way I am trying to do in the above code is right or not.

The code in index.jsp is:

if(response=="existsnoadmin")
 {
    alert(response);
    alert("The value obtained by the admin.java is " +request.getAttribute("rest"));
    out.println("The value obtained by the admin.java is " +request.getAttribute("rest"));
    alert("we have done in index.jsp");
}

The output is that I am getting the alert box which says “existsnoadmin”.

But I am not able to get the value of rest here nor in Admin.java.

What is the mistake I have done here? Please help.

Regards,

Archana.

  • 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-05-20T03:29:40+00:00Added an answer on May 20, 2026 at 3:29 am

    You say that the code in the JSP is this:

    if(response=="existsnoadmin")
    {
        alert(response);
        alert("The value obtained by the admin.java is " +request.getAttribute("rest"));
        out.println("The value obtained by the admin.java is " +request.getAttribute("rest"));
        alert("we have done in index.jsp");
    }
    

    I’m having problems understanding what this really means.

    If the above code is Java code that appears inside scriptlet tags <% … %>, then I don’t understand how alert(response); is showing you anything. In fact, it should give you a compilation error in the JSP.

    On the other hand, if the above is Javascript code that is embedded in the page that the JSP generates, then

    • request.getAttribute("rest") cannot possibly work … because the request object that you set the attribute on does not exist in the web browser, and

    • out.println(...) cannot work because the JspWriter does not exist in the web browser.

    Either you have not transcribed the JSP excerpt accurately, or your Java and/or Javascript doesn’t make sense.


    Based on your comment, I think you need the following.

    if(response=="existsnoadmin")
    {
        alert(response);
        alert('The value obtained by the admin.java is ' +
              '<% request.getAttribute("rest") %>');
        // The value obtained by the admin.java is <% request.getAttribute("rest") %>
    }
    

    Or if you want to get rid of the scriplet stuff …

    if(response=="existsnoadmin")
    {
        alert(response);
        alert('The value obtained by the admin.java is ' +
              '${requestScope.rest"}');
        // The value obtained by the admin.java is ${requestScope.rest"}
    }
    

    If you want the stuff that I’ve turned into a // JS comment to be visible on the page, you been to move it to some content part of the HTML. Currently it is (I assume) inside a <script> element, and therefore won’t be displayed.

    The key to all of this black magic is understanding what parts of a JSP are seen/evaluated by what:

    • JSP directives e.g. <@ import ...> are evaluated by the JSP compiler.
    • Stuff inside scriptlet tags e.g. <% ... %>, EL expressions e.g. ${...} or JSTL tags e.g. <c:out ...\> gets evaluated when the JSP is “run”.
    • Anything generated by the JSP (HTML content, embedded Javascript) is displayed / executed in the user’s browser after the HTTP response has been received.

    Now is it neccessary to use the request.dispatcher….forward command in admin.java.

    Your primary servlet can do one of two things.

    • It can use the request dispatcher to forward the request to your JSP. If it does this it can forward additional values by setting request attributes.

    • It can open the response output stream and write stuff to it.

    It should not attempt to do both! (I’m not sure exactly what will happen, but it is likely to result in a 500 Internal Error.)

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

Sidebar

Related Questions

I have a variable inside my php file, which I want to pass to
I need to pass a regex substitution as a variable: sub proc { my
I need to pass an ID and a password to a batch file at
I need to pass an array from JavaScript to a page method in C#.
I have a java application I need to pass some info to a C++
I'm creating a function where I need to pass an object so that it
I have a user control in a repeater that I need to pass data
I have a .NET program and a Borland Win32 program that need to pass
I have a dict, which I need to pass key/values as keyword arguments.. For
I pass text from a POST variable from a form on my site to

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.