Should a class file always be inside package for importing it in jsp page?

0 votes

I am new to Java and learning to work with JSP. I created a class inside student package, when I import it code worked successfully. But when I omitted the package and place the class "Student" directly in WEB-INF/classes folder, I got an error saying 

Student cannot be resolved to a type. 

I searched alot but did not find any reasonable answer. However, I solved the problem by putting this class inside package, but want to know that is this necessary that class should exist inside package. Thank You

May 24, 2019 in Java by anonymous
334 views

1 answer to this question.

0 votes

Hey there!

It is not necessary for the class to be inside the package if you have you mentioned to import the class in your JSP file. Example:

<%@ page import "com.example.Student" %>

But if you have not, then it is necessary for the class to be placed inside the package.

answered May 24, 2019 by Karan

Related Questions In Java

0 votes
1 answer

How can a war file be deployed in Tomcat 7?

You can access your application from: http://localhost:8080/sample Deploying ...READ MORE

answered Apr 20, 2018 in Java by sophia
• 1,400 points
1,047 views
0 votes
1 answer
+5 votes
3 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 6, 2018 by Omkar 30,259 views
0 votes
2 answers

How can I create File and write data in it using Java?

import java.io.BufferedWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public class WriteFiles{ ...READ MORE

answered Jul 26, 2018 in Java by samarth295
• 2,200 points
297 views
0 votes
1 answer

Importing classes in JSP

Use Page Directive to import a Class ...READ MORE

answered May 25, 2018 in Java by Rishabh
• 3,580 points
6,678 views
0 votes
1 answer

Get parameters from the URL with JSP

To delete the subject record with its ...READ MORE

answered May 28, 2018 in Java by Parth
• 4,630 points
1,153 views
0 votes
1 answer

How can we upload the files using JSP/ Servlets in Java?

<form action="upload" method="post" enctype="multipart/form-data"> ...READ MORE

answered Jun 8, 2018 in Java by Sushmita
• 6,890 points
202 views
0 votes
1 answer

Difference between JSF, Servlet and JSP?

Servlet - it's java server side layer. JSP ...READ MORE

answered Jul 2, 2018 in Java by samarth295
• 2,200 points
536 views
0 votes
3 answers

How to read a Text File in Java?

You can use readAllLines and the join method to ...READ MORE

answered Jul 27, 2018 in Java by samarth295
• 2,200 points
342 views
+2 votes
10 answers

How to import a jar file in Eclipse?

To import jar file in your Eclipse ...READ MORE

answered May 15, 2018 in Java by sharth
• 3,370 points
165,854 views