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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:32:41+00:00 2026-06-12T12:32:41+00:00

I have a java servlet that passes an array to a jsp page, on

  • 0

I have a java servlet that passes an array to a jsp page, on that jsp page it displays a bunch of results. What I am trying to do is when it prints out it prints a link so I can use it as a parameter. In my case it prints out a bunch of lab classes, what i want to happen is they click the link related to that lab then i click the link and can use that lab.id in a sql statement.

here is the code for the array being printed out

here is the servlet

private void sendBack(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession session = request.getSession(true);

        //Set data you want to send back to the request (will be forwarded to the page)
    //Can set string, int, list, array etc.
    //Set data you want to send back to the request (will be forwarded to the page)
    //Can set string, int, list, array etc.
    String sql = "SELECT s.name, l.time, l.day, l.room" +
              " FROM lab l, subject s, user_lab ul" +
            " WHERE ul.user_id=" + (Integer)session.getAttribute("id") +" AND ul.lab_id ="+ "l.id"+" AND l.subject_id ="+"s.id";

  try{
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/wae","root","");
    System.out.println("got boobs");
    System.out.println(session.getAttribute("id"));

      Statement stmt = con.createStatement();
      ResultSet res = stmt.executeQuery(sql);
      System.out.println(res);
      ArrayList<String> list1 = new ArrayList<String>();
      if (res.next()){
          do{
               list1.add(res.getString(1) + " " + res.getString(2) +" "+ res.getString(3) + " " + res.getString(4));
               System.out.print(res.getString(1) +  res.getString(2));
          }while(res.next());
      System.out.println("Outside");
      String[] arr = list1.toArray(new String[list1.size()]);
      request.setAttribute("res", arr);
      }




  }catch (SQLException e) {
    } 
    catch (Exception e) {
    } 


    //Decides what page to send the request data to
    RequestDispatcher view = request.getRequestDispatcher("Lecturer_labs.jsp");
    //Forward to the page and pass the request and response information
    view.forward(request, response); 

and here is the jsp page

<h3>Manage Labs</h3>
<table>
<% String[] list1 = (String[])request.getAttribute("res");
         if(null == list1){%>

<% 
         }else{
        for(int i=0; i<list1.length; i++)
        {   %>
        <tr><%out.println(list1[i] + "<br/>");%></tr>        
    <%  }
        }
        %>
        </table>

so how can I get it to print the results as a link that passes a parameter

  • 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-12T12:32:43+00:00Added an answer on June 12, 2026 at 12:32 pm

    To display the results as a link that pass the parameter id, each link could look like:

    <a href="/myapp/mypage.jsp?id="<%out.println(list1[i]);%>">Link <%out.println(list1[i]);%></a>
    

    but look how clunky this looks.

    JSTL tags can eliminate all this scriptlet code:

    <c:forEach items="${res}" var="id">
       <tr><td><a href="/myapp/mypage.jsp?id=${id}">Link ${id}</a></td></tr>
    </c:forEach>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a decent working web application (Java/Servlet/Jsp) that I would like to improve
i have big trouble with my application that web-application(jsp,java,servlet) landed between two server cause
I have a JSP page which passes the HttpServletRequest and HttpServletResponse to a Java
I have a Java servlet that receives data from an upstream system via a
I have this java servlet that grabs information from a form, I need to
Suppose I have a Java Servlet that takes a while to finish computing it's
I have a legacy Java servlet that is currently running in a Tomcat container.
Our application is a Java-GWT application that uses Guice-Persist and Guice-Servlet extensively. We have
Unix gurus! I have a Java program which passes some parameters to a Servlet
I have developed a java servlet that monitors a folder on a network drive

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.