0

I am developing a Dynamic Web Project in Eclipse IDE for Java EE Developers and I would like to know if it is possible to call a java method from an HTML input tag. To be more specific, I want this <form method="post" action="/Ex2/Servlet1"> to be <form method="post" action="/Ex2/Admin.java/CreateNewUser()">. As you see, I want the input to call the function (CreateNewUser()) of class Admin and then this function to call Servlet1. Admin's function will be in the "middle" of the whole process.

JimHawkins
  • 4,843
  • 8
  • 35
  • 55
Xaris
  • 73
  • 1
  • 7

2 Answers2

0

You can't call a Java method from HTML, HTML is interpreted in the browser and it only can send HTTP requests to a HTTP server, the requests are processed by servlets (apart from filters and other) so you need to have a servlet to process the request.

0

Actually you can call some Java method from your JSP file, adding scriptlet scriptlets but is not a good practice.

I would recommend just use a proper endpoint in your action attribute, send the form to the controller, do all actions you need, create that user and redirect to any page you need.

EDIT KISS :)

To clarify....

https://en.wikipedia.org/wiki/KISS_principle

cralfaro
  • 5,822
  • 3
  • 20
  • 30