Wrote some code as a Java Servlet and I am now trying to use in JSP. I wrote a class in a separate file which I was using, and I can't figure out how to get the JSP file to recognise the class. I guess it has something to do with importing. I gave the class a default package (no name of package) and I tried using <%@ page import=".Register"%>
but I get an error: (Register is my servlet class name..)
so tell me what if i do to import of default package in jsp.
Thanks for all your help!
Asked
Active
Viewed 1,584 times
-1

Drejc
- 14,196
- 16
- 71
- 106

pulkit kothari
- 1
- 3
-
2How about giving a package name and using it ? – Suresh Atta Nov 03 '14 at 07:06
-
Actually i know the syntax <%@ page import="packagename.classname"%> but i want to know when package name is not define means it is default then how to import servlet class in jsp?? – pulkit kothari Nov 03 '14 at 07:22
-
1Well default will be bad practice what about define package and import? – Kishan Bheemajiyani Nov 03 '14 at 07:22
2 Answers
1
You can't import a class from a default package. It's a compile time error. See the Java Specification.
Or you can use reflections
.
For Reflections You Can Visit SO link: Reflections for importing class from default package.
0
Well I think you need to look up JSP Specification and I got idea that you need to specify the package name if you wanted to import into the JSP. I did not know until I read the document.

Chris Martin
- 30,334
- 10
- 78
- 137

Kishan Bheemajiyani
- 3,429
- 5
- 34
- 68