So what I\'m basically trying to do here is get a list of hotels in JSP , from the servlet , without any forms.
This is my JSP:
<%@ page language=
The best way to do that is to use a Tag handler. You won't have to deal with the servlet. Your jsp can invoke the tag handler and get the list of hotels and you can loop over the list, like you are doing in your code.
- ${elem.name}
In the above code HotelSearch is a tag handler created to return search results string.
e.g. hotel1,hotel2,hotel3
The string is later broken down using split and converted into an array.
public class HotelSearch extends SimpleTagSupport {
private String query;
@Override
public void doTag() throws JspException {
JspWriter out = getJspContext().getOut();
try {
//Query the database using a Database Controller.
out.println(DatabaseController.getSearchResult(query));
} catch (java.io.IOException ex) {
throw new JspException("Error in HotelSearch tag", ex);
}
}
public void setQuery(String query) {
this.query = query;
}
}