Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to call Servlet with parameters  RSS feed

 
Syskata Mitev
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have this part of code


and I wont to call to Servlet with parameters #{userbackbean.usernick} and #{userbackbean.password}

thanks a lot.
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Mark
 
Syskata Mitev
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);

Mark
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!