Servlet with Helper method
I have a Servlet in Tomcat that works where it gets parameters from a form and I have condtions for the parameters. Here is an example shortened for this post:
if((fieldOne ==null) && (fieldTwo !=null))
{
varOne ="fieldTwo is populated";
varTwo ="fieldTwo condition setting here";
}
if((fieldOne !=null) && (fieldTwo ==null))
{
varOne ="fieldOne is populated";
varTwo ="fieldOne condition setting here";
}
if((fieldOne !=null) && (fieldTwo !=null))
{
varOne ="fieldOne and fieldTwo are populated";
varTwo ="fieldOne and fieldTwo conditions setting here";
}
Now I want to move this part of the Servlet into a helper class or bean and call it in the Servlet but not sure how to do this?
Here is what I have so far but need help. Please advise.
Helper.java
class Helper()
{
public Helper()
{
//default constructor here
}
public String conditionMethod()
{
if((fieldOne ==null) && (fieldTwo !=null))
{
varOne ="fieldTwo is populated";
varTwo ="fieldTwo condition setting here";
}
if((fieldOne !=null) && (fieldTwo ==null))
{
varOne ="fieldOne is populated";
varTwo ="fieldOne condition setting here";
}
if((fieldOne !=null) && (fieldTwo !=null))
{
varOne ="fieldOne and fieldTwo are populated";
varTwo ="fieldOne and fieldTwo conditions setting here";
}
//return statement here? Not sure how to do this part
}
}
Then call it in Servlet like this?
...
String varOne = Helper.conditionMethod();
...

