Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 16 of 16

Thread: Problem with running the downloaded jsp program

  1. #1
    Junior Member
    Join Date
    Dec 2020
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Problem with running the downloaded jsp program

    Greetings and Regards
    I downloaded the simple project as an exercise from the github site, I opened the project with eclipse, and I created the database and its table in mysql, and I also made the settings related to the connection to the database, but the project gives an error when running. Please run the program yourself once and give guidance. In terms of coding and programming logic, everything is correct, only an unknown problem occurs in the implementation.
    Thanks.
    Link of project:
    github.com/bhiapp4/crudApp
    Last edited by s_s_s; December 8th, 2020 at 03:13 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problem with running the downloaded jsp program

    gives an error
    Please copy the full text of the error message and paste it here. It has important info about the error.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2020
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem with running the downloaded jsp program

    Error messages:
    HTTP Status 500 – Internal Server Error

    Type Exception Report

    Message An exception occurred processing [index.jsp] at line [10]

    Description The server encountered an unexpected condition that prevented it from fulfilling the request.

    Exception

    org.apache.jasper.JasperException: An exception occurred processing [index.jsp] at line [10]

    7: <title>Welcome</title>
    8: </head>
    9: <body>
    10: <jsp:forward page="/StudentController?action=listStudent"></jsp:forward>
    11: </body>
    12: </html>


    Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:626)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:515)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:385)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:329)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:733)
    org.apache.tomcat.websocket.server.WsFilter.doFilt er(WsFilter.java:53)

    Root Cause

    java.lang.NullPointerException
    com.junald.dao.StudentDAOImplementation.getAllStud ents(StudentDAOImplementation.java:68)
    com.junald.controller.StudentController.doGet(Stud entController.java:46)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:626)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:733)
    org.apache.tomcat.websocket.server.WsFilter.doFilt er(WsFilter.java:53)
    org.apache.jasper.runtime.PageContextImpl.forward( PageContextImpl.java:530)
    org.apache.jsp.index_jsp._jspService(index_jsp.jav a:126)
    org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:71)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:733)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:477)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:385)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:329)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:733)
    org.apache.tomcat.websocket.server.WsFilter.doFilt er(WsFilter.java:53)

    Note The full stack trace of the root cause is available in the server logs.
    Apache Tomcat/9.0.40

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problem with running the downloaded jsp program

    java.lang.NullPointerException
    com.junald.dao.StudentDAOImplementation.getAllStud ents(StudentDAOImplementation.java:68)
    com.junald.controller.StudentController.doGet(Stud entController.java:46)
    What variable on line 68 has a null value?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2020
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem with running the downloaded jsp program

    The following code is:
    Statement statement = conn.createStatement();
    But how do I solve it?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problem with running the downloaded jsp program

    If that is line 68, then the conn variable must have a null value. Check the code that assigns a value to conn to see if it is executed properly.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2020
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem with running the downloaded jsp program

    But the value for this variable is set
    Please run the program once

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problem with running the downloaded jsp program

    But the value for this variable is set
    Does conn have a non-null value when line 68 is executed? How do you know that?

    Sorry, I am not setup for executing JSP code.

    Please Post the code that shows where conn is declared, assigned a value and used causing the NPE.

    The StudentDAOImplementation class writes errors to the log. Are there any messages there?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Dec 2020
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem with running the downloaded jsp program

    StudentDaoImpl.java code:
    package com.app.dao;
     
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.List;
     
    import com.app.model.Student;
    import com.app.util.DBConnectionUtility;
     
    public class StudentDaoImpl implements StudentDao{
     
    	@Override
    	public void addStudent(Student student) {
    		try(Connection conn = DBConnectionUtility.getDBConnection()) {			
    			String query = "insert into student (firstName, lastName, course, year) values (?,?,?,?)";
    			PreparedStatement preparedStatement = conn.prepareStatement(query);
    			preparedStatement.setString(1, student.getFirstName());
    			preparedStatement.setString(2, student.getLastName());
    			preparedStatement.setString(3, student.getCourse());
    			preparedStatement.setInt(4, student.getYear());
    			preparedStatement.executeUpdate();
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    	}
     
    	@Override
    	public void deleteStudent(int studentId) {
    		try(Connection conn = DBConnectionUtility.getDBConnection()) {			
    			String query = "delete from student where studentId=?";
    			PreparedStatement preparedStatement = conn.prepareStatement(query);
    			preparedStatement.setInt(1, studentId);
    			preparedStatement.executeUpdate();
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    	}
     
    	@Override
    	public void updateStudent(Student student) {
    		try(Connection conn = DBConnectionUtility.getDBConnection()) {			
    			String query = "update student set firstName=?, lastName=?, course=?, year=? where studentId=?";
    			PreparedStatement preparedStatement = conn.prepareStatement(query);
    			preparedStatement.setString(1, student.getFirstName());
    			preparedStatement.setString(2, student.getLastName());
    			preparedStatement.setString(3, student.getCourse());
    			preparedStatement.setInt(4, student.getYear());
    			preparedStatement.setInt(5, student.getStudentId());
    			preparedStatement.executeUpdate();
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    	}
     
    	@Override
    	public List<Student> getAllStudents() {
    		List<Student> students = new ArrayList<Student>();
    		try(Connection conn = DBConnectionUtility.getDBConnection()) {			
    			Statement statement = conn.createStatement();
    			ResultSet resultSet = statement.executeQuery("select * from student");
    			while (resultSet.next()) {
    				Student student = new Student();
    				student.setStudentId(resultSet.getInt("studentId"));
    				student.setFirstName(resultSet.getString("firstName"));
    				student.setLastName(resultSet.getString("lastName"));
    				student.setCourse(resultSet.getString("course"));
    				student.setYear(resultSet.getInt("year"));
    				students.add(student);
    			}
    		} catch (SQLException e) {
    			e.printStackTrace();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    		return students;
    	}
     
    	@Override
    	public Student getStudentById(int studentId) {
    		Student student = new Student();
    		try(Connection conn = DBConnectionUtility.getDBConnection()) {			
    			String query = "select * from student where studentId=?";
    			PreparedStatement preparedStatement = conn.prepareStatement(query);
    			preparedStatement.setInt(1, studentId);
    			ResultSet resultSet = preparedStatement.executeQuery();
    			while (resultSet.next()) {
    				student.setStudentId(resultSet.getInt("studentId"));
    				student.setFirstName(resultSet.getString("firstName"));
    				student.setLastName(resultSet.getString("LastName"));
    				student.setCourse(resultSet.getString("course"));
    				student.setYear(resultSet.getInt("year"));
    			}
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    		return student;
    	}
    }
    Last edited by s_s_s; December 9th, 2020 at 09:08 AM.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problem with running the downloaded jsp program

    try(Connection conn = DBConnectionUtility.getDBConnection()) {
    What does that code do? Does it return a non-null value to the conn variable?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Dec 2020
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem with running the downloaded jsp program

    connection code:
    package com.junald.util;
     
    import java.io.IOException;
    import java.io.InputStream;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.util.Properties;
     
    public class DBUtil {
     
    	private static Connection conn;
     
    	public static Connection getConnection() {
    		if( conn != null )
    			return conn;
     
    		InputStream inputStream = DBUtil.class.getClassLoader().getResourceAsStream( "/db.properties" );
    		Properties properties = new Properties();
    		try {
    			properties.load( inputStream );
    			String driver = properties.getProperty( "driver" );
    			String url = properties.getProperty( "url" );
    			String user = properties.getProperty( "user" );
    			String password = properties.getProperty( "password" );
    			Class.forName( driver );
    			conn = DriverManager.getConnection( url, user, password );
    		} catch (IOException e) {
    			e.printStackTrace();
    		} catch (ClassNotFoundException e) {
    			e.printStackTrace();
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
     
    		return conn;
    	}
     
    	public static void closeConnection( Connection toBeClosed ) {
    		if( toBeClosed == null )
    			return;
    		try {
    			toBeClosed.close();
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    	}
    }

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problem with running the downloaded jsp program

    Does the call to DBConnectionUtility.getDBConnection() return a valid value for conn?

    Why did you post the code for the DBUtil class?
    What code calls the getConnection method in the DBUtil class?
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Dec 2020
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem with running the downloaded jsp program

    Is it possible for you to connect to my system with AnyDesk software?

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problem with running the downloaded jsp program

    Sorry, I can not run your code.

    Can you answer my questions about the conn variable? Does it get assigned a non-null value?
    Are there any error messages in the server's log files?

    Your problem may be with configuring tomcat and the database. I don't know how to do that.
    There may be people on this forum that know:
    https://coderanch.com/forums
    Try asking your question there.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Dec 2020
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem with running the downloaded jsp program

    The problem was solved!
    The problem was with the driver version of the mysql program, which was older than my version 8 of my sql, which was solved by updating the driver file connection problem with the database.
    Thank you
    Last edited by s_s_s; December 12th, 2020 at 01:26 AM.

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problem with running the downloaded jsp program

    Ok, I am glad you fixed it. Thanks for letting us know what the fix was.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. I have downloaded
    By BeginningProgrammer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 11th, 2017, 08:22 PM
  2. need Help to get this program running
    By adam1991 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 4th, 2014, 11:32 PM
  3. Replies: 21
    Last Post: June 12th, 2013, 11:33 AM
  4. JSP getting downloaded
    By arumilli in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: May 7th, 2012, 11:40 AM
  5. Running into a problem with my program.
    By letsgetlifted in forum What's Wrong With My Code?
    Replies: 9
    Last Post: December 9th, 2011, 07:09 PM