Skip to main content

Featured

Adobe Experience Manager - Create an OSGI Configuration

 In this article, let's create an OSGi configuration, configure it and use it in AEM code. So now let's get started with the creation of an OSGi configuration. Technical details and Assumptions: All the following details are tested in AEM version 6.5.8, Java version 11.0.2 Creation of OSGi configuration: To create an OSGi configuration we need to create an ObjectClassDefinition. I have included a sample OCD configuration, which can be used as a reference to create one. The next step would be to create an interface and an implementation that can help fetch the OSGi configurations.  Interface: Implementation: Let's try to use the OSGi configuration created so far in Models/Servlets. For demonstration purposes, I used AEM Models here, but the same can be implemented in Servlets too. Now that we have created the OSGi configuration. Once building the code, we should be able to see the OSGi configuration in the web console (http://localhost:4502/system/console/configMgr) C...

A Web Application Using Jsp



            To use jsp for with jdbc connectivity all we need is the basic knowledge of java to jdbc connectivity using the jdbc driver. The Basic steps for it is to Import the Jdbc package


   

Index.jsp:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Tech Talk!</h1>
        <form action="Insert.jsp" >
            <input type="text" name="uname" placeholder="User name"/>
            <input type="email" name="email" placeholder="Email"/>
            <input type="password" name="pass" placeholder="Password"/>
            <input type="submit" value="Sign Up"/>
        </form>
    </body>
</html>

Insert.jsp:

/** Step 1: **/
<%@page import="java.sql.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
            try{/** query is the string variable used to hold the queries , so all the mysql or other database queries can be used here **/
                String query = "insert into model (uname,email,pass) values ('"+uname+"','"+email+"','"+pass+"')";
                String query1 = "Select * from model";
                String uname = request.getParameter("uname");
                String email = request.getParameter("email");
                String pass = request.getParameter("pass");
/** Step 2: **/
                Class.forName("com.mysql.jdbc.Driver");
/** Step 3: **/
                Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "");
 /** Step 4:**/
                Statement st = con.createStatement();
/** Step 5: **/
                st.executeUpdate(query);
                ResultSet rs = st.executeQuery(query1);
/** Step 6,7: Can be used with Select query specifically on a ResultSet which is to be create in the same way as the Statement is created, and then processed  **/
                while(rs.next()){
                out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3)+" "+rs.getString(4));
                %>
              <br/>
               <%
            }
/** Step 8:  **/
                st.close();
                rs.close();
/** Step 9: **/
                con.close();    
            }catch(Exception e){
                out.println(e);
            }
           %>
    </body>
</html>
DataBase Name: model

Table Structure:

 

Input: 



Output:

Comments

Popular Posts