I need to create a string (sql statement) which might be pass to 2 or more jsp files. Recommended method is "by accessing the ServletContext attributes via Java scriptlet or the applicationScope via EL". But, is there a simple way to pass the string from java class to the jsp? Something like below?
Java
public class SharedSQL extends HttpServlet{
public String example() {
String sqlstmt = "select ABC from ABC";
return sqlstmt;
}
}
JSP
<%
SharedSQL sqlStatement = new SharedSQL() ;
String sqlstmt = sqlStatement.example();
db4.query ( sqlstmt ) ;
%>
I am new to servlet/JSP 'things', need some hints and tips.