I'd rather not use javascript. I have some code that includes scanner input and was wanting to implement it into my website(html). I've tried SpringBoot but those tutorials weren't what I was looking for. I've uploading a .jsp file but the syntax was not correct. Do you have any tips?
CodePudding user response:
You cannot. The browsers only understand javascript. Java is used as a server side language for server side applications inside an application server like Tomcat or JBoss (if you use Spring Boot you can use an embedded Tomcat), the same (but more powerful in my opinion) way you need an Apache server with a PHP interpreter to serve php pages.
You can use a JSP page. But they are intended for generating HTML in the server side. When you load the HTML in the browser the Java code has ended its execution and you cannot do any interaction with the Java side other than reload the same or other page entirely or using ajax requests. In any case, the Java code is executed in a server, not in the browser.
CodePudding user response:
Firstly, I would just use a file. The file should be named x.js, instead of x.jsp. Then, in HTML, use <script src="x.js"></script>
This is my favorite, and should work well :).