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.
in Servlet do like below
public class SharedSQL extends HttpServlet{
    doGet(request ,response){
         request.setAttribute("sqlstmt", "select ABC from ABC");
    }
}
in jsp do like below
<%
     String sqlstmt = request.getAttribute("sqlstmt") 
     db4.query ( sqlstmt ) ;
%>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With