Those ugly things are called scriptlets and yes, they are considered bad practice since a decade, since the moment that taglibs and EL were born. Nowadays they may be useful for quick prototyping, but really nothing more than that.
Nowadays, you normally use taglibs like JSTL to control the page flow and output. You normally use Expresson Language (EL) to access backend data. You can do fairly a lot at the presentation layer with them. If you comes to a point that it is not possible with either of them and you're forced to grab scriptlets, then the code logic ultimately belongs in a real Java class. You can use a Servlet
class to control/preprocess/postprocess requests, you can use a Filter
class to filter requests, you can use a DAO
class to do the database interaction, you can use a Javabean
class to store/transfer/access data, you can use a Domain
class for business logic, you can use an Utility
class for static tools. Use the JSP where it is intented for: a view technology to write template text like HTML/CSS/Javascript in which provides the possibility to interact with backend Java code and data by taglibs and EL.
Those tutorials are very good to get started with them all the right way: Beginner and Intermediate JSP/Servlet tutorials, Advanced JSP/Servlet tutorials.
That said, the <script></script>
things where you're talking about have by the way nothing to do with Java/JSP. Those are HTML elements which indicate a block of Javascript. This is an entirely independent language with the first 4 characters of the name and a less or more simliar keyword/syntax usage as the only relation to Java.