Friday, September 27, 2013

Installing BIRT in STS



1) Install STS 

2) Click on help -
Install New Software --> Click on Add
-> give the URL (http://download.eclipse.org/birt/update-site/4.2/)

3) Select the BIRT components you want to install--> click Next and follow the instructions such as accept terms and conditions.

4) Click on Finish, it will start installing the BIRT components.

5) It is getting installed successfully and we can see the version details on the following path: Help-
About STS
-> click on Eclipse BIRT Project

Thursday, September 26, 2013

Cookies using JSP / Servlet

Login.jsp

<form action="rem" method="POST">
Enter Value: <input type="text" name="val" value=""/>
<input type="submit" value="Submit" />
</form>

----------------------------------------------------------------------------------
RemController.java

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    String myValue = request.getParameter("val");


    Cookie userCookie = new Cookie("u", myValue);
        userCookie.setMaxAge(60*60*24);
        response.addCookie(userCookie);


    request.getRequestDispatcher("Remember.jsp").forward(request, response);
    }
----------------------------------------------------------------------------------
Remember.jsp

<html>
 <%
        Cookie[] cookies=request.getCookies();
        Cookie cookie=null;
        if(cookies != null){
            for(int i=0; i<cookies.length; i++){
                cookie = cookies[i];
                System.out.print(cookie.getName()+": ");
                System.out.println(cookie.getValue());
            }
        }
        %>
</html>
----------------------------------------------------------------------------------

Wednesday, September 25, 2013

Login Page using Servlet / JSP

1. Servlet Mapping in web.xml

Transfering control from JSP (Login.jsp) file to a servlet (RemController.java) file.
 ----------------------------------------------------------------------------------------------------------------------------
Login.jsp

<form action="rem" method="POST">
Username: <input type="text" id="username" name="username" value=""/><br/>
Password: <input type="password" id="password" name="password" value=""/><br/>
<input type="submit" id="submit" value="Submit" /><br/>

</form>
----------------------------------------------------------------------------------------------------------------------------
web.xml

 <servlet>
    <servlet-name>RemController</servlet-name>
    <servlet-class>myPkg.RemController</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>RemController</servlet-name>
    <url-pattern>/rem</url-pattern>
  </servlet-mapping>
----------------------------------------------------------------------------------------------------------------------------
RemController.java

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setAttribute("result", "hello!");
      
        String name = request.getParameter("username");
        String password = request.getParameter("password");
      
        System.out.println(name+" "+password);
      
    //    response.sendRedirect("Remember.jsp");
        request.getRequestDispatcher("Remember.jsp").forward(request, response);
        }
----------------------------------------------------------------------------------------------------------------------------
Remember.jsp

<html>
<body>
        <h1>Remember.jsp</h1>
        <p>The result is ${result}</p>
</body>
</html>
----------------------------------------------------------------------------------------------------------------------------

Wednesday, September 4, 2013

Database FAQ's

Finding Non-unique rows.

SELECT LIC_NO, count(LIC_NO) AS cnt FROM LM_LICENSE GROUP BY LIC_NO HAVING cnt>1;