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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:43:19+00:00 2026-05-31T08:43:19+00:00

I written a program to retrieve data from database in servlets.now I want pass

  • 0

I written a program to retrieve data from database in servlets.now I want pass this value to jsp as a hyperlink. How to do this?

This is my servlet code what I wrote:

  import java.io.*;
  import java.sql.*;
  import javax.servlet.*;
  import javax.servlet.http.*;

  public class ViewServlet extends HttpServlet{
  public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
  {
  res.setContentType("text/html");
  PrintWriter pw = res.getWriter();
  Connection con;
  Statement stmt;
  ResultSet rs;
  String acid = null;
  try{
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  con = DriverManager.getConnection("jdbc:odbc:DSN","scott","krishna");
  stmt = con.createStatement();
  rs = stmt.executeQuery("Select id from custm where name='jai'");
  req.setAttribute(acid,rs);
  req.getRequestDispatcher("my_jsp_page.jsp").forward(req, res); 
   }
  catch (Exception e){
  pw.println(e);
  }
  }

}

Now I edited the code now its saying cannot call setAttribute with null value.

  • 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-31T08:43:21+00:00Added an answer on May 31, 2026 at 8:43 am

    For extracting value from resultset:

    while (rs.next()) {
    String acid = rs.getString("id");
    }
    

    You can store values in Request scope using setAttribute() method….
    In jsp you can retrieve it using expression language…

    In servlet

    request.setAttribute("acId",acid);
    

    In jsp:

    ${acId}
    

    There is also other way…
    You can also use scriplets for displaying purpose in jsp..
    for example….

    <%  
          String str = (String)request.getAttribute("acId");
    %>
    Value is :: <%= str %>
    

    for calling jsp from servlet use :

    request.getRequestDispatcher("your.jsp").forward(request,response);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had written a program in Python 3, but now want to convert it
I have written a program that uses qhttp to get a webpage. This works
I have written this program, which sorts some ints using a functor: #include<iostream> #include<list>
Basically I've written this program to check for strings. I've used socket method for
I'm new to Python. Here I've written a Python program which retrieves values from
I'm working on a program from my C++ textbook, and this this the first
I have a program that needs to retrieve some data about a set of
I have written a c program that retrieves arguments from the command line under
I have written a function in my program that allows me to retrieve strings
I have written a program in visual basic and want it to display the

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.