To be honest, I am trying to figure out why you would want to call a Servlet. Is the business code and such all tightly coupled in a Servlet?
Anyway, I would have an Action class handle the JSF action from the page, then in the action you can always create a URL object that has the URL for calling the Servlet with the parameters appended to the URL string.
Thanks Mark, I have already servlet that check in mysql database for register users and i wont to call this servlet to log on. How to make Action class handle the JSF action from the page or how to make checking into database in JSF page to understanding the right users. Part of my servlet to check users in database is :
and it's work perfectly. How i can to change it to work in my JSF page or use it from my JSF page. i'm excuse for my unknowing but i try to code and finding the way to do it. Thanks in advance.
OK, so what I would have done in the first place is not to put that code you have in the Servlet in a Servlet, because now you have tightly coupled your Servlet with connecting to the database and coupled the business logic of how to log in to the Servlet. So that code should have been in a Plain Old Java Object that your Servlet could have called, and let your JSF backing Bean/Action class also can call that POJO.
Because you have coupled that code in your Servlet you are now seeing what affect that has in re-use. In order to reuse you would have to put the following code in your JSF backing bean
URL myServlet = new URL("http://www.mywebaddress.com/MyServlet" + myParameters INeedToPassToTheServlet);
//Create Connection, connect to servlet, parse out the returned values from the Servlet, etc...
instead of these two lines
MyReusablePOJOObject reuse = new MyReusablePOJOObject() Result results = reuse.login(userName, password);