Thursday, July 26, 2012

HTML Give border title in div

In HTML to have a table with title in it's border like we can have in swing , we can use div element like shown in below code snipet

<div  style="width:100%;">
    <fieldset>
    <legend style="color:blue;font-weight:bold;">Initiator Information</legend>


      <table  border="0" cellpadding="0" cellspacing="5" >
        <tr>
          <td width="146">User Id</td>
          <td width="216"><label for="userId"></label>
            <input type="text" name="userId" id="userId" /></td>
          <td width="122">Name</td>
          <td width="474"><input type="text" name="userName" id="userName" /></td>
        </tr>
        <tr>
          <td>Department</td>
          <td><label for="userDepartment"></label>
            <input type="text" name="userDepartment" id="userDepartment" /></td>
          <td>Division</td>
          <td><label for="userDevision"></label>
            <input type="text" name="userDevision" id="userDevision" /></td>
        </tr>
      </table>
     
    </fieldset>
    </div>


The above code will show the div in browser like below




Tuesday, July 24, 2012

Enabling HTTPS In J2EE Web Applications

If you want to enable HTTPS configuration in your J2EE web application  then you should add the following lines in web.xml file under your WEB-INF folder.

<security-constraint>

            <display-name>MyWebApp</display-name>
           
            <web-resource-collection>
           
                        <web-resource-name>MyWebApp</web-resource-name>
                       
                        <description/>
                       
                        <url-pattern>/*</url-pattern>
                        <http-method>GET</http-method>
                        <http-method>POST</http-method>
            </web-resource-collection>
            <user-data-constraint>
                        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
            </user-data-constraint>
</security-constraint>

this will redirect any attempt to use your application on HTTP to HTTPS.

Monday, July 9, 2012

Can't get basic Hello World Spring MVC project to work , Spring MVC Project , Maven: Failed to retrieve plugin descriptor error

Ok after banging my head with STS for 1 day I finally found the easy way to configure spring mvc project in STS.

 Below is the summary of easy steps to do

1) Download latest STS and install it
2) Configuring JDK and other things is easy so do that along with the wizard
3) Open STS select File --> New --> Other --> Spring Source Tool Suite --> Spring Template project --> Spring MVC Project and follow the Wizard to create a new project
4) Once it's done you will see STS showing you errors in the project code , and that is because the Maven dependencies are not downloaded yet.
5) Right click on the project select  run --> Maven Clean and then right click again on the project select run--> Maven install
If this step shows you error in console while running Maven then you have to do following steps

a) In STS click on windows --> Preferences --> General --> Maven --> Installations --> look at the folder where maven is being installed on my machine it is on

D:\Users\sajjadparacha\Downloads\springsource\apache-maven-3.0.3

b) open the Maven folder and go to conf folder , open settings.xml file and add below proxy setting xml

<proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>userName</username>
      <password>password</password>
      <host>proxy address</host>
      <port>80</port>
    </proxy>   

c) Don't forget to mention your user name , password and proxy address and save the settings.xml file.

6) Now come back to STS , right click on the project and select run --> Maven Clean and then run --> Maven Install . Now if your proxy settings are correct STS should build and install your project correctly and will download all the dependencies.
7) Right Click on your project and select run--> on server and you should see the Hello world page.

I wish this will help some one some day out there :).
Would be happy to have comments if you find it helpful or if you want to suggests any changes.



Wednesday, June 20, 2012

Invalid Column type : get_internal_type


Sometimes you are so sure that your application running fine on testing server will also work fine on production as both environment have same data and the data in test was actually imported from production so no problem will occur , well life is not that easy for us the software solution providers J.

Today after finishing the requirements from a user in one of my systems and after testing it fully with test data I was going to deploy the application on production environment. Before doing that luckily I tried it with production data and realized it was giving me a wired exception  “Invalid Column type : get_internal_type”.
So again the same application was working fine in test environment which always have the data imported from production , After Googling this exception message we found out that the problem could have been with the data in one of the fields in our resultset.
It was hard to find but thanks to my colleagues Huthaifa,Syed Baqir Ali we were able to find the root cause of this problem which was the problem with the data in “rowid”  in our queries we were selecting the rowid property and it appeared that in JDBC code when we were trying to get the rowid from result set for some records it was giving us this exception and for some it was getting the rowid properly.
We are trying to get the row id by calling toString() method on ResultSet which for the problematic rowids was throwing this exception “Invalid Column type : get_internal_type”.
The only solution is to use the oracle function “rowidtochar”  to get the row id e.g

Select  a.*, rowidtochar(a.rowid) row_id from student

This way the JDBC code will never throw the exception for this column , now the only reason behind this problem could be rowid generated by oracle sometimes have non-character values and when we try to get the value from Resultset using toString() it can’t parse it to String (However it’s strange how oracle’s own JDBC implementation is not handling this case J , we are using OJDBC6).

Sunday, May 8, 2011

Applet/Swing/Flex/J2ME to Servlet Communication Why I am losing JSESSIONID (on weblogic 11) and what's the solution.

We have an application which was built using Applet, Servlet and JSP technologies.
The Application has been on production since last 2-3 years and was working perfectly fine on WebLogic 10G. Recently we were asked to deploy our applications on WebLogic (10.3.3) 11g , and we found that the same application (Which is working fine on WebLogic 10.3.0.0) was crashing on WebLogic 10.3.3.
After doing some research and debugging code we found that the problem was actually with Applet Servlet communication as Applet was not passing JSESSIONID to servlet as a result the server was unable to find the Session associated to the client and application was crashing.
The confusing point was that the same code was working perfectly fine on older version i.e. WebLogic 10.3.0.0.
After digging the code we found that we were using java.net.URLConnection from Applet to connect to servlet and were assuming that this will take care of JSESSIONID while connecting the server, this assumption was right for WebLogic10.3.0.0 but not for WebLogic 10.3.3.
So the solution is to store the JSESSIONID at client end (APPLET) and always send the JSESSIONID from applet to servlet.
For reference you can see the following forum post
http://www.jguru.com/faq/view.jsp?EID=33978
And especially following post
I just did some tests, and it appears that using URLConnection() the applet is automatically returning the sessionId that the servlet sets (also automatically). That is, in both IE5 and NN4, without explicitly adding anything to the header the applet was sending back, the servlet was able to recognize the sessionId as the same across repeated calls from the same applet. So my guess is that if you run your applet from within one of these browsers, they automatically add in the cookies to all your URLConnections. Any naysayers?
And in response following post
And did you do tests for more versions of java (1.1.4, 1.3, 1.4.2)? Is this behavior described in Applet specification or is it an accident? If it is not a standard then it could stop work in future versions of Java
Note: If we send JSESSIONID with all the requests to servlets we can get rid of issue of finding no session on servlet end.

Summary:
When you communicate with a servlet from Applet/Swing or any other application and you face the problem of not finding the appropriate session on server you should first check the communication of JSESSIONID between your application and server and if your application is not properly sending JSESSION ID than you can do it yourself by rewriting JSESSIONID in URL. And it can also be a best practice if you take care of JSESSIONID communication you don’t have to relay/assume anything about the APIs you are using for your application to servlet connection and this solution will always work.

Monday, April 11, 2011

corejava: java.sql.SQLSyntaxErrorException: ORA-01747: inval...

corejava: java.sql.SQLSyntaxErrorException: ORA-01747: inval...: "I got this exception yesterday while trying to execute an insert statement through JDBC and found out that their was an error in the query ,..."

java.sql.SQLSyntaxErrorException: ORA-01747: invalid user.table.column, table.column, or column specification

I got this exception yesterday while trying to execute an insert statement through JDBC and found out that their was an error in the query , following is an example of where I was doing wrong

let's say the orignal working query was initially

insert into abc (a,b,c) values (?,?,?)

then I added another column d in the table abc and updated the above query like

insert into abc (a,b,,c,d) values (?,?,?,?)

when trying to execute above query I was getting this exception , notice that mistakenly I had one extra comma in the field list , I deleted the comma

insert into abc (a,b,c,d) values (?,?,?,?)

and the query was running fine after that.