Friday, August 12, 2011

Converting Jsp/Html Form Values To XML

Requirements:

1. For this i used Castor Framework, it makes my work simple.
   http://www.castor.org/download.html

Go for the  " Full documentation including all JavaDocs and specs (big) "
b'cos it includes all the dependency jar files.

2. Include those Jars project.

Procedure:

Write a Jsp with minimal form elements and calling to servlet or action.
i called action in this example.




<form name="sample" action="AccessDB" method="get">

<table>

<tbody><tr>

<td>CUSTOMER Id</td>

<td> <input type="text" name="custid" value="" size="15" /></td>

</tr>

<tr>

<td>CUSTOMER NAME</td>

<td><input type="text" name="name" value="" size="25" /></td>

</tr>

<tr>

<td>DISCOUNT ID</td>

<td><select name="discountid">

<option>H</option>

<option>M</option>

<option>L</option>

<option>N</option>

</select></td>

</tr>

<tr><td> ZIP</td>

<td><input type="text" name="zip" value="" size="10" /></td>

</tr>

<tr>

<td><input type="submit" value="Submit"/></td>

</tr>

</tbody>

</form>


Here AccessDb is servlet.
below is the servlet code:



CustomerBean cb=new CustomerBean();

cb.setCustid(request.getParameter("custid").toString());

cb.setName(request.getParameter("name").toString());

cb.setDiscountid(request.getParameter("discountid").toString());

cb.setZip(request.getParameter("zip"));




FileWriter writer = new FileWriter("/home/miracle/Desktop/cbs.xml");

Marshaller.marshal(cb, writer);



CustomerBean  is a normal pojo class with normal setters and getters. 

It will create a XMl file on specified path.

<?xml version="1.0" encoding="UTF-8"?>
<customer-bean><discountid>H</discountid><name>Venkat</name><custid>1003</custid><zip>53662</zip></customer-bean>

Friday, August 5, 2011

CronTab Usage

Actual Syntax Of CronTab

* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)


 Task: Run the file daily at 11:30pm

30---> Minutes
23---> Hours
*  ---> DayOfthemonth
*  ---> Month
*  ---> Week

will call the "sample.sh" file at every day 11:30pm

To enter new cron Job,  type in terminal : crontab -e

30 23 * * * /home/sample.sh        


The above specified cron job will on every day

we have restart the crond service to get it effective.

  • # /etc/init.d/crond start
  • # /etc/init.d/crond stop
  • # /etc/init.d/crond restart

To See List Of CronJobs:

  •  # crontab -l

To Edit CronJob:  #crontab -e

After Edit you have to restart the "crond"  service to make it effective.