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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:42:48+00:00 2026-06-12T10:42:48+00:00

hi all I’ve typed out a page that queries the database then inputs something

  • 0

hi all I’ve typed out a page that queries the database then inputs something into the database but when I go to load the servlet/jsp page its comes back blank and am unsure what is happening or why? I’m coding in eclipse and after looking at the console and not getting anything printing out I figured there was something wrong with my code but I cannot see the problem.

Here is my servlet

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class TutorAssign
 */
@WebServlet("/TutorAssign")
public class TutorAssign extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public TutorAssign() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

    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.

         String sql = "SELECT l.id,s.name,l.day,l.time,l.room" +
                  " FROM subject s, lab l " +
                    " WHERE s.user_id="+(Integer)session.getAttribute("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>();
              ArrayList<String> list2 = new ArrayList<String>();
              if (res.next()){
                  do{
                       list1.add(res.getString(1));
                       list2.add(res.getString(2)+" "+res.getString(3)+" "+res.getString(4)+" "+res.getString(5));


                  }while(res.next());
              System.out.println("Outside");
              String[] arr1 = list1.toArray(new String[list1.size()]);
              String[] arr2 = list2.toArray(new String[list2.size()]);
              System.out.println(list1);
              request.setAttribute("res1", arr1);
              request.setAttribute("res2", arr2);

              }



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


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

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


          int user_id = Integer.parseInt(request.getParameter("id"));
          int lab_id = 0;

          String message = null; 
          try {
              Class.forName("com.mysql.jdbc.Driver");
              Connection con = 
                DriverManager.getConnection("jdbc:mysql://localhost:3306/wae","root","");
            System.out.println("got connection"); 
            System.out.println(user_id);
            Statement s = con.createStatement(); 

            String sql = "INSERT INTO user_lab" + 
                      " (user_id, lab_id)" + 
                      " VALUES" + 
                      " ('" +  user_id + "'," + 
                         " '"  +  lab_id + "')"; 

              System.out.println(sql);
              int i = s.executeUpdate(sql); 
              if (i==1) {
                message = "Successfully assigned a tutor."; 
                response.sendRedirect("Lecturer_labs");
              } 

              s.close(); 
              con.close(); 
            } 
            catch (SQLException e) {
              message = "Error." + e.toString(); 
              boolean error = true; 
            } 
            catch (Exception e) {
              message = "Error." + e.toString(); 
              boolean error = true; 
            } 
            if (message!=null) {
              PrintWriter out = response.getWriter(); 
              out.println("<B>" + message + "</B><BR>"); 
              out.println("<HR><BR>"); 
            } 

          } 
// TODO Auto-generated method stub


}
  • 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-12T10:42:49+00:00Added an answer on June 12, 2026 at 10:42 am

    I noticed that your doGet method has not been implemented.
    I would assume that your sendBack code is not being called

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       sendBack(request,response);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All my PHP pages work fine but there is one PHP page that used
All, If I've go the following database fields/values: user_id field_name field_value 1 EventHour1 1
All I want to do is return the index of the i that is
all. We're trying to get some intersect collisions working, but the problem experience is
All the guys probably will recommend that I read the follow previously question in
All, I have some script tags that are not working in Wordpress. If I
All programs that I develop utilize the default Windows Design template: Besides from changing
all I want to calculate the height of the page ,and in my test.less
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
All, I am trying to create a table to receive user inputs (UGC). This

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.