Java – Import classes in JSP files
I wrote some code as a java servlet, and now I'm trying to convert it to JSP I wrote a class in a separate file and I'm using it. I can't figure out how to make the JSP file recognize this class I think it has something to do with importing I gave a package (package mypackagename;) Name, I tried to use <% @ page import = "mypackagename"% > but I received an error:
Solution
Just import it as in a real Java class Import mypackagename Myclassname or import mypackagename. *, Therefore, mypackagename.xml will not be imported using only the package name
<%@ page import="mypackagename.MyClassName" %>
That is, you should not write raw java code in JSP files Scriptlets are considered bad practice This code belongs to the real Java class Its place in the servlet class is very good What is it, and what do you think is the problem of moving "all" to the view side and confusing the template text with the original java code? Explain it in detail in a new problem, and then we can suggest the correct solution Maybe you don't know the existence and power of taglib like JSTL?