But i thought i should stayed back and attened some of the session which i decided earlier.Any way next time i won't concetrate on BOJUG alone, which ever i find interesting i will attened that's what i am having in my mind ok cool i am waiting for BCB5
Tuesday, July 31, 2007
But i thought i should stayed back and attened some of the session which i decided earlier.Any way next time i won't concetrate on BOJUG alone, which ever i find interesting i will attened that's what i am having in my mind ok cool i am waiting for BCB5
Friday, July 27, 2007
I was looking a way to create a shortcut for locking the workstation, XP has windows+l shortcut key, But there is cute way to create the shortcut for locking workstation.Go to your winnt folder, be careful find rundll32.exe and create a shortcut place it in desktop.Now go to the properties of the shortcut which you created before and look in to the target, add the below content to the target after a space from the existing one user32.dll,LockWorkStation,Rename your shortcut to Lock and try to click it.Oops! ....it works
Tuesday, July 24, 2007
In developing web application security is the most important one,for example a web application is running on port number 8080 (default for tomcat) the application name be Sample.For connecting the application we will
the type the following address in the url http://localhost:8080/Sample and then logging inside the application the url changes as you click the pages and navigate inside the app.Try to collect any of the url from the app that your r navigating and and paste in different browser if that particular page is opened then your app needs as security checks.In Java there is cool concept called Filters.
Filters are are application-level Java code components within a J2EE Web application.They can act as gatekeeper's to your web-app checking the logging in credentials, validating from which page request came and the other very useful things
In the web.xml you have to define the filters
<filter>
<filter-name>AuthFilter</filter-name>
<filter-class>com.filter.AuthFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>AuthFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
In the above mapping whatever request goes to your web-app it is first intercepted by Filter
Filter has ServletRequest and ServletResponse you need it to type cast to HttpServletRequest and HttpServletResponse for getting the username from the request and session. The Logic of the below program is simple.
we are checking whether the request comes from the loginpage if yes the user has entered username in the loginpage so the parameter we are getting using request and checking whether that value is null if it is not null then setting that value to session and leaving the process to application.
If the request is not from the loginpage we are checking whether the username is in session if yes then allow him to go through the app if not throw the user to login page and ask him to enter
Sample Filter Code
public class AuthFilter implements Filter {
private FilterConfig config;
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
this.config=arg0;
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
/* Type Casting request and response */
HttpSession session = ((HttpServletRequest) request).getSession();
ServletContext context = config.getServletContext();
HttpServletResponse serresponse=(HttpServletResponse)response;
/*
* use the ServletContext.log method to log filter messages
*/
String AUTH_PAGE="/LoginPage.jsp";
String username=null;
String sessusername=null;
String filename=null;
HttpServletRequest serrequest=null;
serrequest=(HttpServletRequest)request;
/* Getting the File Name */
filename=serrequest.getServletPath()+serrequest.getPathInfo();
/* Checking the File Name*/
if(AUTH_PAGE.equals(filename))
{
/* Getting the username from the MainPage */
username=serrequest.getParameter("usernname");
if(username==null)
{
sessusername=(String)session.getAttribute("usernname");
if(sessusername==null&&sessusername.trim().equals(""))
{
serresponse.sendRedirect(serrequest.getContextPath()+AUTH_PAGE);
}
serresponse.sendRedirect(serrequest.getContextPath()+AUTH_PAGE);
}
session.setAttribute("username",username);
chain.doFilter(request, response);
}
else
{ if(session.getAttribute("username")!=null&&!session.getAttribute("username").toString().trim().equals(""))
{
chain.doFilter(request, response);
}
else
{
serresponse.sendRedirect(serrequest.getContextPath()+AUTH_PAGE);
}
}
}
public void destroy() {
}
}
Powered by ScribeFire.
Sunday, July 15, 2007
We had a requirement of reading a xml file from the WEB-INF folder of web-app
and to build a xml document from the file, after building the document its very much easy to
parse through the document and get the date.Here are the steps and code-snippets to do it.
Since its a web-app we need to get the ServletContext.
ServletContext context = pageContext.getServletContext();
After getting the context we need get the file as Stream for building xml document
InputStream inputStream=context.getResourceAsStream("/WEB-INF/example.xml");
We have got the inputStream we need a build the xml document.The below DomRead.java
will build the document
Document document = DomReadUtil.parse(inputStream);
public class DomRead
{
public static Document parse(InputStream stream )
{
Document document = null;
// Initiate DocumentBuilderFactory
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// To get a validating parser
factory.setValidating(false);
// To get one that understands namespaces
factory.setNamespaceAware(true);
try
{
// Get DocumentBuilder
DocumentBuilder builder = factory.newDocumentBuilder();
// Parse and load into memory the Document
document = builder.parse(stream);
return document;
}
catch (SAXParseException spe)
{
// Error generated by the parser
System.out.println("\n** Parsing error , line " + spe.getLineNumber()
+ ", uri " + spe.getSystemId());
System.out.println(" " + spe.getMessage() );
// Use the contained exception, if any
Exception x = spe;
if (spe.getException() != null)
x = spe.getException();
x.printStackTrace();
}
catch (SAXException sxe)
{
// Error generated during parsing
Exception x = sxe;
if (sxe.getException() != null)
x = sxe.getException();
x.printStackTrace();
}
catch (ParserConfigurationException pce)
{
// Parser with specified options can't be built
pce.printStackTrace();
} catch (IOException ioe) {
// I/O error
ioe.printStackTrace();
}
return null;
}
}
Now we got the XMLDocument document we can parse the xml document and get the
information we need.
Note :
The inputStream passing to the DomRead.java should be opened or Read, if so it will give
Premature End Of File - SaxParseException.
ServletContext context = pageContext.getServletContext();
InputStream inputStream=context.getResourceAsStream("/WEB-INF/example.xml");
StringBuffer sb=new StringBuffer();
BufferedReader br=new BufferedReader(new InputStreamReader(inputStream));
while(br.readLine()!=null)
{
sb.append(br.readLine()+"\n");
}
System.out.println("fpath "+sb.toString());
Document document = DomReadUtil.parse(inputStream);
The above code will give you Premature End Of File - SaxParseException.Because we have opened the inputStream and Read the contents.when trying to build the Doc from the stream,its already read.so there is premature end of file
Tuesday, July 10, 2007
Selecting a particular row in Datatable – JSF
Selecting a particular row in Datatable in a web-app which is developed on JSF,If the requirements is to display data in the datatable with check boxes in every row and user will select a particular row and then clicks the respective buttons to do the operation.
Html Page for Displaying DataTable
Sample:
<table align="center">
<tr>
<td>
<h:dataTable border="1" cellpadding="2" cellspacing="0" headerClass="headerClass" footerClass="footerClass"
rowClasses="rowClass1" styleClass="dataTable" value="#{beanname.data}" var="pagination" binding="#{beanname.datatable}">
<h:column>
<f:facet name="header">
<h:outputText value="Select"/>
</f:facet>
<h:selectBooleanCheckbox id="selectid" styleClass="selectBooleanCheckbox" binding="#{beanname.checked}">
</h:selectBooleanCheckbox>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Header Variable"/>
</f:facet>
<h:outputText value="#{pagination.headerid}"/>
<h:inputHidden id="hidden" value="#{pagination.variable2}" binding="#{beanname.variable2}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Header Variable1"/>
</f:facet>
<h:outputText value="#{pagination.variable2}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Header Variable2"/>
</f:facet>
<h:outputText value="#{pagination.variable3}"/>
</h:column>
</h:dataTable><BR>
<h:commandButton value="Opertion1" action="actionparam" id="Opertion1ID" >
<f:actionListener type="ListenerClassName" /></h:commandButton>
<h:commandButton value="View Opertion1" action="actionparam1" id="Opertion2ID" >
<f:actionListener type="com.anz.cpr.listener.TransactionHeaderListener" /></h:commandButton>
<h:commandButton value="Opertion1 TxHeader" action="actionparam2" id="Opertion3ID">
<f:actionListener type="ListenerClassName" />
</h:commandButton>
</td></tr>
</table>
Java Bean which holds the data (Backing Bean)
This bean is used by the above page to display the data
beanname.methodname
getData() method returns a list which contains the DB data
In the Bean create a method which will return a list which contains bean Object
Sample :
Public class SampleBean
{
private String variable;
private String variable1;
private String variable2;
private UISelectBoolean checked;
private UIData datatable;
public List tbllist;
/* Getter Setter Methods for variable1,2,3 and for other variables*/
public List getData()
{
/* Query DB and get the Resultloop through the result setsample i am using hibernateget Session for hibernate*/
List hquery=session.createQuery("from XYZ").list();
if (hquery != null && hquery.size() > 0)
{
tbllist=new ArrayList(hquery.size());
for (int i=0; i< hquery.size(); i++)
{
Tblxyz xyz=(Tblxyz)hquery.get(i);
SampleBean bean=new SampleBean();
/* get value from the db and set in the bean */
tbllist.add(bean);
}
}
}
}
ListenerBean
Since we are Implementing ActionListener we need implement the methods
public BeanListener implements ActionListener
{
public void processAction(ActionEvent event) throws AbortProcessingException
{
/* This will give the id name of the particular h-link which
* generated this action
* /
String sCommandName=event.getComponent().getId();
/*Getting the faces context*/
FacesContext context=FacesContext.getCurrentInstance();
/* Since we have three H-links we are cheking which one got triggred
* i.e operation1ID got triggred now i need that particular row data
*/
if(sCommandName.equals("Opertion1ID"))
{
ValueBinding valueBinding=Util.getValueBinding("#{beanname}");
SampleBean samplbean=(SampleBean)valueBinding.getValue(context);
/* since we have used binding the jsf we can get the entire datatable from the JSF page*/
UIData datatable=samplbean.getDatatable();
/* getting the totalRowCount */
int rowCount=datatable.getRowCount();
/* Looping through the datatable to check which row got selected*/
for (int index = 0; index < hvalue="samplbean.getVariable2().getValue().toString();">
Friday, June 29, 2007
The server maintains a buffer for the content that is to be written out to the client. When this buffer is filled to capacity the default action is to flush the content to the client while fresh content is loaded into the buffer.Now, it is illegal to do a forward once the output is committed i.e the buffer has been flushed to the client - this is the source of the error('Response already been committed') .To solve this problem you will have increase the size of the buffer from the default size ( this depends on the application server you are using) to a size,which will not overflow until all the page content is loaded into it so that you have suffcient time to decide if you must flush the buffer to the client or clear the buffer so that you may forward it to the error page.
To increase the buffer size, include the page directive in the JSP page , the page directive would look like this :
<%@ page page-attribute-list %>
In the attribute list for the buffer attribute provide a size in KB - this will be by trial and error as if the size of your Header , Sidebar exceed your buffer size the buffer would be flushed.Another attribute that you may set is auto flush the default value of which is true. If you set it to false it becomes your responsibility to flush the buffer when it is full.
Note : I faced this problem and i found this answer in one of the sun forums and thought good answer ..let me share it ..
Tuesday, June 26, 2007
Here's yogi-b & natchatra's link click here
Sunday, June 24, 2007
This week end i was watching (Neeya - Naana ) program with my friends and came across some interesting news. the topic was - what are the qualities
(no this is not the correct word) material things(ya !.got it) a boy should have before marriage.Leaving aside all the things that girls said abt the quality they need from a boy.
Girls listed some of the M things they need from a boy
pts collected as top
1 . own house (double bedroom atleast 1200 sq ft) 20 L (In Metros)
2. Two Wheeler 40K - new one
20K - old one
3. Credit-Card ( with add on) 30K - (Credit Limit apprx)
4. Sufficient Money (Hot Cash) 40K
these are the pts that they told and it comes around 20 - 21 lakhs.
So guys b4 thinking of marriage ......plan (to attack any of the banks to rob) to get those things onboard
we enjoyed a lot ....apart from these we got to know ..some good points..
cool man still our girls respect some of our traditions and they doesn't want break those..
One question to girls that if a person doesn't have these things and the guy so promising and he yet to acheive some thing will a girls accept that kind of boy?
And most of the girls (all the girls ) said that they will accept the boy
Good .....nice question and nice answer.......
Sunday, June 17, 2007
...Thinking ......
Wednesday, May 30, 2007
One of the most awaited movies from RajiniKanth at last yet to release on June 15 all over the world. Its really a great festival for R - fans(RajiniKanth Fans).The Trailer of the movie was released today just have a look.Like everybody else i am also awaiting our Thalavar's Movie
Sivaji - the Boss
Trailers Link
You-Tube
http://www.youtube.com/v/dAnTSvywGjc
CNN - IBN - click here
Some Extra Photos
Tuesday, May 08, 2007
Today I found a tool which makes U more addictive to keyboard Colibri this tool makes use of command line and GUI in a nice way such that for launching any application from your desktop or programs you no need to use mouse just use the shortcut key ctrl+space and type the program name it will give all program name that matches
you can select from them you can download colibri
Wednesday, April 04, 2007
1. In your standalone client
Context initialContext=null ;
Properties properties=new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
properties.put(Context.PROVIDER_URL,"iiop://machineip:portnumber");
initialContext=new InitialContext(properties);
DataSource datasource = (DataSource)initialContext.lookup("DataSourceName");
connection=datasource.getConnection("username","password");
2. Add following jars
a. j2cImpl.jar
b.naming.jar
c.naminngclient.jar
d.ojbdc14.jar
If you are not passing username and password to the getConnection method you will get a exception
Thursday, January 25, 2007
Today i searched all the blogging sites to get a blog site with "deja-vu" as URL(literally website name) all of them has been already registered. so i planned to set that name as my blog title and use my name as URL. I have just started let me see how far i can update my blog.