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

The Archive Base Latest Questions

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

Hi all I have a website where a Lecturer assigns a tutor to a

  • 0

Hi all I have a website where a Lecturer assigns a tutor to a lab, Currently I have a list of tutors where I can click assign and then it takes the user to another page where there is a drop down box and they can select which lab they would like the tutor to teach. It’s supposed to submit the id of the lab and the id of the user to the database.

Currently When a user gets the tutor list, they click a link called ‘assign’ which puts the tutors id up in the url, then they have a list of tutes they can select, once I’ve selected the tute and click submit I get the following error.

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.NumberFormatException: null
    java.lang.Integer.parseInt(Unknown Source)
    java.lang.Integer.parseInt(Unknown Source)
    TutorAssign.doPost(TutorAssign.java:97)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

the sendBack method is running but the doPost is not and it’s pointing to the line where I get the request parameter as being null – int user_id = Integer.parseInt(request.getParameter("id"));

how can i fix this? I’ll include the entirety of my servlet for better clarification

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 {
        sendBack(request, response);
    }

    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.
         int user_id = Integer.parseInt((String)request.getParameter("id"));
         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 a hj");
            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);
              request.setAttribute("user_id", user_id);

              }



          }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((String)request.getParameter("id"));
          System.out.println(user_id);
          int lab_id = 0;
          System.out.println("I got a blow job");
          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


}

here is my jsp code

<form name ="TutorAssign" ACTION="TutorAssign" method="post">
        <input type="hidden" name="user_id" value="user_id"/>
        <select name="lab_id">
        <%
        for(int i=0; i<list1.length;i++)  
        { 
        out.println("<option value="+list1[i]+"> "+list2[i]+" </option>");

        } %>
        </select>
        <input type=SUBMIT value="Submit" name="Submit" />

        </form>
  • 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-12T11:01:43+00:00Added an answer on June 12, 2026 at 11:01 am

    The problem is here:

    <form name ="TutorAssign" ACTION="TutorAssign" method="post">
            <select name="labs">
            <%
            for(int i=0; i<list1.length;i++)  
            { 
            out.println("<option value="+list1[i]+"> "+list2[i]+" </option>");
    
            } %>
            </select>
    

    More specifically:

    <select name="labs">
    

    If you would either change the name to id OR use request.getParameter("labs"), you will probably get what you want.

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

Sidebar

Related Questions

Dear all I have database of website link, it list out in main file
I'm currently scraping a website and have all the useful data I need, although
Hi all Currently I have a website that has a button and some javascript
I have website, usually all looks fine but sometimes one div is on the
I have a website with several forms that all pass the same set of
I have a website providing me with 200GB of hosting space. All the files
I have a website with friendly urls. I want all url´s that end with
I have a website that I built a while ago. All of sudden, without
The question pretty much says it all. I have a joomla website and I
I have almost created a website that works in all major browsers flawlessly. Yesterday,

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.