tag:blogger.com,1999:blog-27608578863159293632024-03-14T02:06:29.182-07:00Dev talks blogDarko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.comBlogger42125tag:blogger.com,1999:blog-2760857886315929363.post-91661864841655403902010-10-31T09:53:00.000-07:002010-10-31T09:55:15.209-07:00Ajax XML response and Struts2Ajax and Struts2 are really cool! I really enjoy combining these two together in my web applications.<br />
Few days ago I was working on some application, and needed to update some values in my JSP using Ajax. I decided to use XML as an Ajax response, parse it and do whatever I want with it...<br />
<br />
In this post I will show you how to make Struts2 return XML as an Ajax response.<br />
<br />
Here is an example of how you can do this:<br />
<br />
<pre class="java" name="code">public class CustomAction extends ActionSupport
{
public HttpServletResponse getResponse()
{
return ServletActionContext.getResponse();
}
@Override
public String execute() throws Exception {
PrintWriter printWriter = null;
getResponse().setContentType("text / xml;charset = UTF-8");
getResponse().setHeader("Cache - Control", "no - cache");
StringBuffer sb = new StringBuffer("<movie>");
// let's say you have A Movie object "movie" that needs to be represented as XML
try
{
printWriter = getResponse().getWriter();
sb.append("<director>" + movie.getDirector() + "</director>");
sb.append("<language>" + movie.getLanguage() + "</language>");
sb.append("<year>" + movie.getYear() + "</year>");
sb.append("</movie>");
printWriter.print(sb.toString());
}
catch (IOException e)
{
e.printStackTrace();
throw e;
}
finally
{
printWriter.close();
printWriter = null;
}
return NONE;
}
}
</pre><br />
And that's it! Just create a PrintWriter, adjust some values in response and print your XML.<br />
<br />
And now, in your JavaScript, you can parse this xml and do something with it:<br />
<br />
<pre class="javascript" name="code">directors=xmlhttp.responseXML.documentElement.getElementsByTagName("director");
languages=xmlhttp.responseXML.documentElement.getElementsByTagName("language");
years = xmlhttp.responseXML.documentElement.getElementsByTagName("year");
director = directors[0].firstChild.nodeValue;
language = languages[0].firstChild.nodeValue;
year = years[0].firstChild.nodeValue;
document.getElementById('director').value=director;
document.getElementById('language').value=language;
document.getElementById('year').value=year;
</pre><br />
That's it.<br />
I hope I helped someone...Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com3tag:blogger.com,1999:blog-2760857886315929363.post-75957909139110437252010-08-21T05:40:00.000-07:002010-08-21T05:43:06.068-07:00Just another implementation of string splitting function in PL/SQLHere are some of my implementation of string splitting function in PL/SQL.<br />
It is something developers need often, and still can't believe there isn't a function that does something like this in oracle 10g...???<br />
<br />
Some developers parse delimited text using substr(text,X,Y) for every token they need to use in their code…<br />
<br />
My advice is: Don’t ever do this!!! Use some available tokenizer function!<br />
<br />
I found several implementations on the internet, but those functions either does not support delimiter with length more than 1, either it does not return tokens that are NULL, or does not return table of varchar2 index by pls_integer ( what I needed), etc.<br />
<br />
So I wrote it myself…<br />
<br />
Anyway, here is my first implementation, written entirelly in PL/SQL:<br />
<br />
<pre class="sql" name="code">CREATE OR REPLACE FUNCTION splitString(str VARCHAR2,delimit VARCHAR2) RETURN dbms_sql.Varchar2_Table IS
inputString VARCHAR2(32000);
delimiter VARCHAR2(32);
delimiters dbms_sql.Number_Table;
tokens dbms_sql.Varchar2_Table;
array_index PLS_INTEGER := 1;
pos PLS_INTEGER := 1;
delimiter_pos PLS_INTEGER;
delimiter_length PLS_INTEGER;
inputString_length PLS_INTEGER;
BEGIN
IF str IS NULL THEN
RAISE_APPLICATION_ERROR(-20000,'str cannot be null!');
END IF;
IF delimit IS NULL OR delimit = '' THEN
RAISE_APPLICATION_ERROR(-20000,'delimiter cannot be null or empty string!');
END IF;
inputString := str;
delimiter := delimit;
delimiter_length := length(delimiter);
inputString_length := length(inputString);
-- Prepare inputText for parsing
IF substr(inputString,inputString_length - delimiter_length + 1,delimiter_length) != delimiter THEN
inputString := inputString || delimiter;
END IF;
IF substr(inputString,1,delimiter_length) = delimiter THEN
inputString := substr(inputString,delimiter_length + 1,inputString_length);
END IF;
---------------------
-- find delimiter occurrences in inputText
LOOP
delimiter_pos := instr(inputString,delimiter,pos);
EXIT WHEN delimiter_pos = 0;
delimiters(array_index) := delimiter_pos;
array_index := array_index + 1;
pos := delimiter_pos + delimiter_length;
END LOOP;
--------------------
-- reset temp variables
array_index := 1;
pos := 1;
---------------------
-- iterate through delimiters and create tokens
FOR j IN delimiters.first..delimiters.last LOOP
tokens(array_index) := substr(inputString,pos,delimiters(j)-pos);
array_index := array_index + 1;
pos := delimiters(j)+ delimiter_length;
END LOOP;
--------------------
RETURN tokens;
END;
/
</pre>Function’s parameters are string that needs to be tokenized, and a delimiter ( that can have length greater than 1).<br />
<br />
Yoy could enchance it by setting <br />
<br />
<br />
TOKENS DBMS_SQL.VARCHAR2_TABLE;<br />
<br />
to <br />
<br />
TYPE t IS TABLE OF varchar2(32000) INDEX BY PLS_INTEGER;<br />
TOKENS t;<br />
<br />
if you are dealing with tokens of length > 2000.<br />
Also, these are case-sensitive functions. You can make it case-insensitive very easy...<br />
<br />
<a href="http://www.baze-podataka.net/2009/09/15/oracle-split-string-tokenizer/">Dejan</a> gave me an idea to write it using SQL.<br />
So I did it, because his implementation using SQL to parse a string is cool:<br />
<br />
<br />
<br />
<pre class="sql" name="code">CREATE OR REPLACE FUNCTION SPLITSTRING_USING_SQL(STR VARCHAR2, DELIMIT VARCHAR2)
RETURN DBMS_SQL.VARCHAR2_TABLE IS
INPUTSTRING VARCHAR2(32000);
INPUTDELIMITER VARCHAR2(32);
TOKENS DBMS_SQL.VARCHAR2_TABLE;
DELIMITER_LENGTH NUMBER;
INPUTSTRING_LENGTH NUMBER;
BEGIN
IF STR IS NULL THEN
RAISE_APPLICATION_ERROR(-20000, 'str cannot be null!');
END IF;
IF DELIMIT IS NULL OR DELIMIT = '' THEN
RAISE_APPLICATION_ERROR(-20000,
'delimiter cannot be null or empty string!');
END IF;
INPUTSTRING := STR;
INPUTDELIMITER := DELIMIT;
DELIMITER_LENGTH := LENGTH(INPUTDELIMITER);
INPUTSTRING_LENGTH := LENGTH(INPUTSTRING);
-- Prepare inputText for parsing
IF SUBSTR(INPUTSTRING,
INPUTSTRING_LENGTH - DELIMITER_LENGTH + 1,
DELIMITER_LENGTH) != INPUTDELIMITER THEN
INPUTSTRING := INPUTSTRING || INPUTDELIMITER;
END IF;
IF SUBSTR(INPUTSTRING, 1, DELIMITER_LENGTH) != INPUTDELIMITER THEN
INPUTSTRING := INPUTDELIMITER || INPUTSTRING;
END IF;
SELECT SUBSTR(INPUTTEXT,
INDEKS + DELIMITER_LENGTH,
NAREDNI - DELIMITER_LENGTH - INDEKS) TOKEN BULK COLLECT
INTO TOKENS
FROM (SELECT INDEKS,
LEAD(INDEKS) OVER(ORDER BY INDEKS) NAREDNI,
INPUTTEXT
FROM (SELECT LEVEL INDEKS,
INPUTSTRING INPUTTEXT,
INPUTDELIMITER DELIMITER,
(CASE
WHEN SUBSTR(INPUTSTRING, LEVEL, DELIMITER_LENGTH) =
INPUTDELIMITER THEN
1
ELSE
0
END) IS_DELIMITER
FROM DUAL
CONNECT BY LEVEL <= LENGTH(INPUTSTRING))
WHERE IS_DELIMITER = 1)
WHERE NAREDNI IS NOT NULL;
RETURN TOKENS;
END;
/
</pre>It’s basically very similar to his function.<br />
The only difference is that unlike Dejan’s function, this one returns NULL tokens too…<br />
<br />
You can test theese two functions easy:<br />
<br />
<br />
<pre class="sql" name="code">declare
input VARCHAR2(32000) := 'one***two***three***four***five***six***seven***eight***nine***ten';
delimiter varchar2(10) := '***';
result dbms_sql.Varchar2_Table;
begin
result := splitString(input,delimiter);
--result := splitString_using_sql(input,delimiter);
for i in result.first..result.last loop
dbms_output.put_line(result(i));
end loop;
end;
</pre><br />
<br />
<br />
<br />
<br />
Conclusion:<br />
There are CERTAINLLY better ways to write this function, and these are just an example how this could be done.<br />
<br />
This is one possible approach, to return an array of tokens. For me , probably the better way would be to create an Object that does something like StringTokenizer Java class. Not to return an array, but to provide a way to iterate through tokens using it’s hasMoreTokens() and nextToken() methods. <br />
I think this is better approach if you are dealing with very large input strings and tokens. If you are dealing with small ones, then it’s OK to use one of my funtions I provided here, or any other similar to this one, that you can find on the internet…<br />
<br />
If you intend to use one of these, I suggest on using first one, because It is much faster than second one.<br />
<br />
I didn’t do any optimizations ( which is obvious ) because I was pleased with speed. Of course, you are welcome to do it yourself<br />
<br />
as a matter of fact, I did some speed testing with input strings whose length is ~ 30000, and the first one was (much) faster than many functions I found on the internet…Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com0tag:blogger.com,1999:blog-2760857886315929363.post-41885490734722727712010-02-27T14:44:00.000-08:002010-02-27T14:54:22.390-08:00Nakon dugo vremena, opet sam tu...E zaista nisam odavno pisao na svom blogu. Vjerovatno su najveći razlog za to prevelike obaveze na poslu. Radilo se i dan i noć, pa umor uradi svoje.<br />
Drugi razlog je i nedostatak inspiracije. Pretpostavljam da je to direktna posljedica prvog razloga. Ustvari kada razmislim, više je to nedostatak snage a ne inspiracije ( hm, što je opet posljedica prvog razloga? ) jer sam inspiracije za interesantne teme proteklih mjeseci imao na pretek:<br />
od best practice -a prikupljenih prilikom posljednjeg projekta koristeći Struts2 u sklopu e-governement-a, preko kreiranja JAVA framework-a za rapidni ( uz to i deklarativni ) razvoj web aplikacija , do know-how tema prilikom učešća na razvoju web servisa različitih vrsta i namjena ( koje bi mnogima uštedjele mnoooogo vremena i živaca ) i još mnogih drugih interesantnih stvari...<br />
Zaista sve interesantne teme za pisanje, ALI kao što rekoh – umor učini svoje i tu se vraćamo na početnu rečenicu ovog teksta.<br />
I tako ja pomislih da nisam odavno pisao za blog, i taman da po ko zna koji put po redu uhvatim maglu od pisanja, sjetih se da je danas 27. Februar…<br />
E to je dan koji zaslužuje da se pomene, te ja na ovaj nacin dajem svoj doprinos popularizaciji IT-a u CG: Danas se završava još jedan festival IT-a , ovaj put onaj na Žabljaku: IT 2010!<br />
Doduše, mnogo bi , vjerovatno, smisla imalo da sam se javio 24. Februara, kada je festival pocinjao, ali ni na ovaj nacin ne gubi na “težini” moj doprinos popularizaciji domacih IT festivala :-)<br />
Volio bih kada bi vidjeo i ostale kolege kako na svom blogu pišu o istom. <br />
Ili slicnom, bio bih zadovoljan. <br />
O blogu nekog izlagača i da ne pričam. <br />
Nego, udaljismo se od teme...<br />
Na žalost, ni ove godine nisam posjetio pomenuti festival, i iskreno mi je žao. Jedino što sam mogao ispratiti i procitati u vezi njega je ono što je objavljeno na zvanicnom sajtu ( www.it.ac.me.)<br />
Ove godine je imalo tema koje su me iskreno zainteresovale.<br />
<br />
Prva je <br />
<blockquote>- MOGUCNOSTI PRIMJENE SERVIS-ORIJENTISANE ARHITEKTURE (SOA) U PRAKSI jer imam srece da na poslu aktivno koristim ovakvu arhitekturu pri kreiranju informacionih sistema, i jer je tema koja me poprilicno interesuje a tako se malo zna o njoj kod nas. <br />
Kao što procitah negdje: web servisi su kao srednjoškolski sex: svako prica o njemu, a niko ili rijetko ko ga zaista konzumira. A i onaj ko ga konzumira – ne zna ga pravilno konzumirati. <br />
Nevjerovatno je kako je malo dobrih tekstova i literature na internetu ( napominjem dobrih ) na ovu temu a ima toliko toga da se kaže i demonstrira. Upravo zbog toga me svaka prica na ovu temu interesuje. </blockquote><br />
Druga je <br />
<blockquote>- PRIMJENA MPI ZA ODREÐIVANJE BIASA I VARIJANSE KUBICNE FAZNE FUNKCIJE. Ova tema mi je posebno interesantna. Prvi razlog su koautori na ovom radu koji su mi odredeni garant kvaliteta samog rada, a drugi je jer se radi o aplikaciji radenoj za klaster, upotrebom MPI funkcija. Tokom 2006-e godine sam ucestvovao na izradi prve crnogorske aplikacije za klaster ( koliko sam informisan ) , u sklopu CIS-a UCG (http://www.mren.ac.me/eilenberger/ ) i zaista bi mi bilo interesantno vidjeti kako je neko drugi implementirao nešto slicno...</blockquote><br />
I treca je<br />
<blockquote>- PRIMJER VALIDACIJE XML-A POMOCU DTD-A. Opet kao prvo radi koautora a onda i zbog moje redovne i vrlo ceste upotrebe ovog formata. XML je cesta tema i na ovom blogu...</blockquote><br />
<br />
Ovo, naravno, nisu jedine teme vrijedne slušanja, ali MENI su najinteresantnije. Ne bi bilo loše da su na zvanicnom sajtu obezbjedeni i video snimci predavanja. Eto dobra predlog za organizatore za sljedecu godinu...Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com4tag:blogger.com,1999:blog-2760857886315929363.post-45234035705810295822010-02-04T04:30:00.000-08:002010-02-04T04:57:04.817-08:00Oblikujte novi Oracle Forms builderPrenosim svoj novi tekst sa bloga <a href="http://www.baze-podataka.net/">baze-podataka.net</a><br />
( <a href="http://www.baze-podataka.net/2010/02/04/oblikujte-novi-oracle-forms-builder/">http://www.baze-podataka.net/2010/02/04/oblikujte-novi-oracle-forms-builder/</a> )<br />
<br />
<br />
Nedavno je na Oracle-ovom forumu pokrenuta tema na kojoj možete predložiti šta bi bilo dobro da se doda u Oracle Forms.<br />
<br />
<a href="http://forums.oracle.com/forums/thread.jspa?threadID=1021732&start=0&tstart=0">http://forums.oracle.com/forums/thread.jspa?threadID=1021732&start=0&tstart=0</a><br />
<br />
Na ovaj način je ljudima koji koriste ovaj alat je data sjajna prilika da oblikuju narednu verziji Forms-a.<br />
Naravno, neće se svaki predlog prihvatiti, ali vrijedi pokušati... <br />
<br />
Lično, prve stvari koje su mi pale na pamet su<br />
<br />
<b>- dodavanje kalendarčića</b> ( ovo trenutno radim preko Java binova, ali bi bilo puno bolje imati neki gotovi formsov objekat )<br />
<b>- poboljšanje editora PL/SQL-a</b> ( trenutni editor je više nego smiješan. Čak kada razmislim - ne znam za gori )<br />
<b>- ugrađena podrška za webutil </b>( nepotrebno zakomplikovano )<b><br />
</b><br />
<b>- bolje odrađena podrška za slike </b>( slike importovane preko Image item-a su neprihvatljivo loše )<b><br />
</b><br />
<b>- bolje urađena podrška za kreiranje i importovanje Java binova </b>( nepotrebno zakomplikovano, bez ozbiljnog modula u samom IDE-u koji bi developerima pomogao pri kreiranju binova )<b><br />
</b><br />
<b>- veća sloboda pri kreiranju i oblikovanju data blokova</b>. ( Npr. da se može zadati upit na osnovu kojeg će se u run time-u izgenerisati data blok ( ok, koji bi bio read-only ) . Npr. kao data grid koji imamo u BCB-u, .NET-u... .)<br />
<br />
Naravno, ima još toga čime bi se trebalo pozabaviti u formsu, kao što je npr. debugger, VCS , prelaženje sa aplet aplikacija na ajax aplikacije , standardizacija IDE-a itd i još dosta dosta toga...<br />
<br />
Dakle, ko ima ideje - neka predloži...Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com0tag:blogger.com,1999:blog-2760857886315929363.post-77706153704968666292009-11-28T04:46:00.000-08:002010-01-21T06:27:09.365-08:00NetBeans subversion update issueFor me , NetBeans is the best IDE I tried so far…<br />
And believe me, I tried and used plenty…<br />
I’m not talking about Java IDE only, but IDE in general…<br />
<br />
But there’s a bug in it that made me wonder if there is a need for me to look for another IDE to use when developing applications.<br />
<br />
At one moment , I considered moving to Eclipse, maybe a community edition of IntelliJ IDEA, or even a JDeveloper. <br />
After a while I decided not to switch to other IDE in the middle of the project, and I doubt I’ll be moving after because I found a solution to a problem I’ll be talking about now…<br />
After all, this is the only serious issue i have with NetBeans so far…<br />
<br />
So, what is it about?<br />
<br />
I noticed that every now and then , after I update my local project from subversion repository , I have a problem deploying it…<br />
Just for the record: project in the subversion I updated to is a fully legal and working project.<br />
<br />
NetBeans manage to update it, but when I try to deploy a project, all I get is an exception saying:<br />
<br />
<br />
<span style="font-size: small;"><span style="color: red; font-size: xx-small;">Caused by: Action class […some Action class…] not found - action - file:/C:/Documents%20and%20Settings/Darko/My%20Documents/NetBeansProjects/MyProject/build/web/WEB-INF/classes/struts.xml:714:99</span><span style="font-size: xx-small;"><br style="color: red;" /></span><span style="color: red; font-size: xx-small;"> at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:405)</span><span style="font-size: xx-small;"><br style="color: red;" /></span><span style="color: red; font-size: xx-small;"> at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:355)</span><span style="font-size: xx-small;"><br style="color: red;" /></span><span style="color: red; font-size: xx-small;"> at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:460)</span><span style="font-size: xx-small;"><br style="color: red;" /></span><span style="color: red; font-size: xx-small;"> at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:265)</span><span style="font-size: xx-small;"><br style="color: red;" /></span><span style="color: red; font-size: xx-small;"> at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:111)</span><span style="font-size: xx-small;"><br style="color: red;" /></span><span style="color: red; font-size: xx-small;"> at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:189)</span><span style="font-size: xx-small;"><br style="color: red;" /></span><span style="color: red; font-size: xx-small;"> at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)</span><span style="font-size: xx-small;"><br style="color: red;" /></span><span style="color: red; font-size: xx-small;"> ... 28 more</span><br style="color: red;" /></span><br />
<br />
<br />
But there is no message saying what’s wrong…<br />
As I said, this was a quite frustrating, and it still is, but now I know how to solve it and continue my work…<br />
<br />
All you need to do is restart Netbeans and try to deploy your project again.<br />
You’ll fail.<br />
But now , you’ll get a message in your output window saying that some of your classes, is missing.<br />
Find which one is “missing”.<br />
It is not really missing. For some reason NetBeans is just saying it cannot “see” it…<br />
Go to source packages and open this class.<br />
Go to the end of it and just enter few new lines in it and click “save”.<br />
Let NetBeans save it, and then do a right-click on the project and click “Build” and hit the “Clean and Build” button…<br />
<div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicJBSrRqMKUHdVCCdDBLk9YkCPcAh8nGKxa4L_5Kdx1CRURK0buNK71WvJP38RbFF8-y-61x64dIUVTc6CrwHg3C9wQKOTk_HvJN3-F96ue_mVF-84DOABQE8S1QtEiM_IJcqsr7EbCYs/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicJBSrRqMKUHdVCCdDBLk9YkCPcAh8nGKxa4L_5Kdx1CRURK0buNK71WvJP38RbFF8-y-61x64dIUVTc6CrwHg3C9wQKOTk_HvJN3-F96ue_mVF-84DOABQE8S1QtEiM_IJcqsr7EbCYs/s400/1.png" width="260" /></a><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div style="text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi58PuUD6PPt6V9Jz160WNzUBpsYLkCrjEPCgE49oK6EiD5GXSi-66LIBt09wgKjAtSkfNnDsXPmLY3HSbAdNJKg5Bmlx-aDOdhftJVCXclg2qpM2W-_xlVgLAL96CkwwJYOpCC2cpcLgI/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="145" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi58PuUD6PPt6V9Jz160WNzUBpsYLkCrjEPCgE49oK6EiD5GXSi-66LIBt09wgKjAtSkfNnDsXPmLY3HSbAdNJKg5Bmlx-aDOdhftJVCXclg2qpM2W-_xlVgLAL96CkwwJYOpCC2cpcLgI/s400/2.png" width="400" /></a><br />
</div><div style="text-align: center;"><br />
</div><div style="text-align: left;">Now try to deploy it…<br />
You’ll probably succed…<br />
I know I do!<br />
<br />
If you don’t, do all the process once again…<br />
Not ALL the process, just the one after restarting NetBeans.<br />
<br />
I would really like to see this bug fixed.<br />
I don’t know if this is really a NetBeans bug, or a Subversion bug, or Tomcat bug ( I use Tomcat ) but it exists…<br />
<br />
As I said, this is the only serious bug I found so far in NetBeans , and would really like to hear from you if there is a way of solving somehow different… Some regular way …<br />
<br />
<br />
</div>Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com0tag:blogger.com,1999:blog-2760857886315929363.post-82865323236660276952009-11-27T10:57:00.000-08:002010-01-21T06:27:35.321-08:00Oracle OpenScript<div class="separator" style="clear: both; text-align: center;"><br />
</div>Nema, Oracle je zaista Interesantan...<br />
Ono što on napravi MORA ostaviti utisak na vas!<br />
Makar na mene ostavlja...<br />
<br />
Nekad cete biti zaprepašceni kako je Oracle nešto loše i/ili nestandardno uradio ( npr. Oracle-ova konzola, code editor u Oracle forms-u, oracle designer, odredene specifičnosti PL/SQL-a… i još mnogo toga) , a nekad ( uglavnom ) cete biti zapanjeni kvalitetom uradenog ( npr. Oracle Discoverer , ADF , oracle Reports, APEX , web util ... i još mnogo toga )<br />
E, postoji jedan alat koji je posljednji u nizu ostavio više nego pozitivan utisak na mene.<br />
Njegovo ime je Oracle OpenScript.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIKGb7BJWt5YlhCOraGf8Fv0Cfa4i3vIhTbiO-uP_cYTSGl6sBwp3FfAhSuVeY4dCCmiFcyie-b28Z1frV7VF3Zj2Uj8jDvqAOmqd6iesnmg-HqjvMJJ8ovGIQFaZULHhWP7_qxJbvdJ0/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="256" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIKGb7BJWt5YlhCOraGf8Fv0Cfa4i3vIhTbiO-uP_cYTSGl6sBwp3FfAhSuVeY4dCCmiFcyie-b28Z1frV7VF3Zj2Uj8jDvqAOmqd6iesnmg-HqjvMJJ8ovGIQFaZULHhWP7_qxJbvdJ0/s400/1.png" width="400" /></a><br />
</div><div style="text-align: center;"><br />
</div><div style="text-align: left;">Svi koji rade na razvoju Oracle Forms ili klasicnih web aplikacija ce biti više nego oduševljeni onim što ovaj alat ima da ponudi.<br />
<br />
Rijec je o Eclipse-based IDE-u u kojem možete kreirati skriptove za automatizovano testiranje vaših aplikacija.<br />
<br />
<br />
Ja ga još nisam detaljno ispitao, ali i sa ovoliko malim iskustvom sa Oracle openScript-om oduševljeno tvrdim da je ovo jedna nova stavka mome spisku must-have alata za razvoj forms i web aplikacija.<br />
I upravo je stigao u savršenom trenutku, što se mene tice!<br />
<br />
Kreiranje ogromnih formi je upravo postao mnogo lakši posao ?<br />
<br />
E kad se samo sjetim dugometražnih unosa podataka i beskonacnih pozivanja novih i novih formi i LOV-ova da bi dobio samo jednu logicku cjelinu unutar baze novog IS-a zarad testiranja uradenog…<br />
Pa ako nešto ne valja, ispraviš to i sve iz pocetka…<br />
<br />
Kako se radi sa Oracle openScriptom?<br />
<br />
Ono što sam ja do sada vidjeo – jako jednostavno!<br />
<br />
Kreirajte script za automatizovano testiranje vaše aplikacije, <br />
</div><div style="text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyaHS5XYqmq3qyWC2S-ehHtfTNfu7zhUszeJ_uXZ8KnprC-ro_IqhM8jc9-0Zg8UA5fPWY4x_QK2yG59FNkO9SHUklGN-Xm4j1nl38wSKgdKZrHhzceUmg0zKgfUBiqv03cxG17imiR7M/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyaHS5XYqmq3qyWC2S-ehHtfTNfu7zhUszeJ_uXZ8KnprC-ro_IqhM8jc9-0Zg8UA5fPWY4x_QK2yG59FNkO9SHUklGN-Xm4j1nl38wSKgdKZrHhzceUmg0zKgfUBiqv03cxG17imiR7M/s400/2.png" width="400" /></a><br />
</div><div style="text-align: center;"><br />
</div><div style="text-align: left;">i dobicete novi prayan script sa defaultnim cjelinama :<br />
<br />
- initialize<br />
- run<br />
- finish<br />
</div><div style="text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpvWduLxkR9JdPxpKhJF5_yXHkVI4SOMH-0-jYTwz62ZGkukUivFnbRzadq4D5JaBKIUW0x8b8JbTqCozIiCcRN7HsoCm5zt-Ucrm5SeGYAfN6OgEE-j-E3SbfU1b8FMI46VeTOSu5f0/s1600/3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="298" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpvWduLxkR9JdPxpKhJF5_yXHkVI4SOMH-0-jYTwz62ZGkukUivFnbRzadq4D5JaBKIUW0x8b8JbTqCozIiCcRN7HsoCm5zt-Ucrm5SeGYAfN6OgEE-j-E3SbfU1b8FMI46VeTOSu5f0/s400/3.png" width="400" /></a><br />
</div><div style="text-align: center;"><br />
</div><div style="text-align: left;">Rijec je ustvari o vizuelnoj prezentaciji java coda koji se generiše u pozadini, tj. Na jezicku “Java code”<br />
</div><div style="text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhETmFFsVdgOGx0cy5qhGtaCd-v9vVRiLE3uZCCZb934DJiIcRkStDLbJxmu_54mGmBjc0tnbUuMxLfQgZtMbJPbAP4S3IOSPp95s_DHH47CK3hdkSrT2wKQSDmXUA8gfUEEljsIh1OJew/s1600/4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="297" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhETmFFsVdgOGx0cy5qhGtaCd-v9vVRiLE3uZCCZb934DJiIcRkStDLbJxmu_54mGmBjc0tnbUuMxLfQgZtMbJPbAP4S3IOSPp95s_DHH47CK3hdkSrT2wKQSDmXUA8gfUEEljsIh1OJew/s400/4.png" width="400" /></a><br />
</div><div style="text-align: center;"><br />
</div><div style="text-align: left;"><br />
</div><blockquote><i>The OpenScript Tree View scripting interface provides a graphical representation of the test script. Multiple script windows can actually be open at the same time. Within each script window, the Tree View is broken down into 3 main script sections: </i><br />
<i>• Initialize: For script commands that only execute once on the first iteration</i><br />
<i>• Run: Main body of the script for commands that will run on every iteration</i><br />
<i>• Finish: For script commands that only execute once on the last iteration</i><br />
<i>Within each section, script Steps and Navigation nodes can be created automatically during script recording or manually through the Tree View user interface. Additional script commands will also be represented as nodes in Tree View including test cases, data inputs, log messages, etc. Each Tree View node has a corresponding representation in the Java Code View. </i><br />
</blockquote><div style="text-align: left;"><br />
<br />
<br />
A kako se to Javin kod generiše?<br />
<br />
Pa, po onome što sam vidio , najjednostavnije npr. klikom na dugme “record” .<br />
Kada kliknemo na ovo dugme, otvorice nam se defaultni browser ( ovo možete promjeniti u podešavanjima unutar samog okruženja ) i Oracle openScript ce na osnovu vašeg djelovanja generisati script ( Java code ) koji ce biti code-prezentacija onoga što ste vi uradili prilikom testiranja.<br />
Dakle, IDE sve pamti, I upravo ce , kada kliknete na dugme “playback” sve sam ponovo uraditi.<br />
Sve adrese koje upišete u adres bar , sve na šta kliknete, koje sve popup ili nove prozore otvorite, koji sve prozori preuzmu fokus, sve ce se “pamtiti” u kodu kreiranjem poziva prema odgovarajucim funkcijama API-ja koji Oracle OpsenScript koristi.<br />
<br />
Sjajna stvar!<br />
<br />
Ovo je, naravno, najlakši nacin za generisanje skripta.<br />
Postoji i rucno pisanje koda, koje je sigurno naprednije i mocnije, i mnoge druge funkcionalnosti koje IDE nudi, ali kažem – nisam ga mnogo koristio da bih mogao prenijeti tips and tricks…<br />
<br />
U svakom slucaju – u pitanju je stvarcica kojoj cu sigurno pružiti šansu. Još jedna od onih iz Oracle-ovih laboratorija koja vas ostavi bez daha…<br />
<br />
<br />
Dakle, ko je zainteresovan da isproba, i olakša sebi život, download strana je:<br />
<a href="http://www.oracle.com/technology/software/products/app-testing/index.html">http://www.oracle.com/technology/software/products/app-testing/index.html</a><br />
<br />
Ko želi koristiti Oracle openScript sa Oracle Forms developerom , evo i jedan lijep link sa kratkim uvodom u tu materiju:<br />
<br />
<a href="http://www.scl.com/software-quality/software-quality-resources/testing-oracle-forms-with-openscript">http://www.scl.com/software-quality/software-quality-resources/testing-oracle-forms-with-openscript</a><br />
<br />
<br />
Cujemo se, nadam se , uskoro na ovu temu ponovo... ;-)<br />
<br />
</div>Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com0tag:blogger.com,1999:blog-2760857886315929363.post-61007599443240036192009-10-19T12:13:00.000-07:002010-08-21T05:43:51.779-07:00Oracle ROWNUMNa baze-podataka.net je izašao moj novi post, ovaj put posvećen priči o <b>rownum</b>-u u Oracle RDBMS-u.<br />
<br />
Tema može biti interesantna ljudima koji ranije nisu detaljnije čitali o ovoj pseudo koloni.<br />
Objašnjeno je njeno pravilno korišćenje u upitima , i skrenuta pažnja na neke česte zablude u vezi <b>rownum</b>-a...<br />
<br />
Link: <a href="http://www.baze-podataka.net/2009/10/19/oracle-rownum/">http://www.baze-podataka.net/2009/10/19/oracle-rownum/</a>Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com0tag:blogger.com,1999:blog-2760857886315929363.post-43340734936280300012009-10-07T01:59:00.000-07:002010-01-21T06:14:32.656-08:00Struts2 config-browser pluginGreat thing that I recently discovered in struts2 is the ability of exploring the entire configuration that Struts2 uses to run your application by just including one <b>.jar</b> file - Struts2 config-browser plugin.jar<br />
<br />
Using this plugin is quite easy…<br />
All you need to do is to add <b>struts2-config-browser-plugin-2.x.x.jar</b> to your project.<br />
No other action is required!<br />
Now, after you deploy your project, open config-browser by calling <b>index.action</b> inside <b>config-browser </b>namespace.<br />
<br />
for example:<br />
<br />
http://localhost:8084/MyApp/config-browser/index.action<br />
<br />
After you run it, you’ll get a page containing entire configuration of you application.<br />
You can click on any action you have mapped inside your struts.xml and see all the parameters set for it…<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXNWGvDKzfzSsiqrtm5sZEDtMG6l5L-juy0NTB5agvBybGyBcowl1Ie4lDbn-NIyLe31HNjBRIgk4jXG00SeXXVpvLu9PPMGzUB964PtDhC3umL1HQeh6XOFdgyWU5DNv-LXy-a69NX84/s1600-h/plugin.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXNWGvDKzfzSsiqrtm5sZEDtMG6l5L-juy0NTB5agvBybGyBcowl1Ie4lDbn-NIyLe31HNjBRIgk4jXG00SeXXVpvLu9PPMGzUB964PtDhC3umL1HQeh6XOFdgyWU5DNv-LXy-a69NX84/s320/plugin.gif" /></a><br />
</div><br />
<br />
<br />
<br />
And not only actions!<br />
You can explore the struts constants too, for example…<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXrxEnzFiZvsYawmlFXPG8827LYQon5btKlW8FRSeAHWLY4KSe8jiApEkx0b6OZSazJL9nF3P8U_FPsnqpMTJ3hCQNrc_JZhmjMP0EPYTsRDqywxV-au3F0w0Pk-mRnGiMFy6jxGZZsy0/s1600-h/plugin1.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXrxEnzFiZvsYawmlFXPG8827LYQon5btKlW8FRSeAHWLY4KSe8jiApEkx0b6OZSazJL9nF3P8U_FPsnqpMTJ3hCQNrc_JZhmjMP0EPYTsRDqywxV-au3F0w0Pk-mRnGiMFy6jxGZZsy0/s320/plugin1.gif" /></a><br />
</div><div style="text-align: center;"><br />
</div>and other things…<br />
<br />
Try it! You could fine some interesting things, and it could actually help you when developing or maintaining application…Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com2tag:blogger.com,1999:blog-2760857886315929363.post-51374099886209684942009-09-24T00:57:00.000-07:002010-01-21T06:17:26.484-08:00Creating struts2 login page using Tomcat 6 and JNDI realmCreating login module when using Struts2 and tomcat can be quite cool and interesting assignement, but can also be a quite annoying job if you are not familiar with all that you need to do…<br />
<br />
When creating this module, there are several approaches. For example:<br />
<br />
- Creating login module using container managed security<br />
- Creating programmatic login module where you define a “database” of usernames, passwords, and roles. This way you define your login logic by yourself as well.<br />
- Using some 3rd party library<br />
<br />
This post describes how to configure Tomcat 6 to support container managed security, using JNDI realm.<br />
I’ll use JNDI realm that enables application server to look for user’s information within Active Directory.<br />
<br />
Realms are really cool!<br />
They are, in fact, an instruction for application server on where to look for user names, passwords and roles when a user that tries to login into your application needs to be authenticated or sometimes it’s a “database” of usernames, password and roles itself.<br />
Great thing when using container managed security is that everything is already implemented, and all you have to do is to provide a realm and map several elements in web.xml, regarding security.<br />
<br />
Let’s start from the beginning.<br />
At this moment, my web.xml file looks like this:<br />
<br />
<br />
<blockquote style="color: #666666;"><?xml version="1.0" encoding="UTF-8"?><br />
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><br />
<br />
<filter><br />
<filter-name>struts2</filter-name><br />
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class><br />
</filter><br />
<filter-mapping><br />
<filter-name>struts2</filter-name><br />
<url-pattern>/*</url-pattern><br />
</filter-mapping><br />
</blockquote><br />
<blockquote style="color: #666666;"> <session-config><br />
<session-timeout><br />
15<br />
</session-timeout><br />
</session-config><br />
</blockquote><br />
<blockquote style="color: #666666;"> <welcome-file-list><br />
<welcome-file>index.jsp</welcome-file><br />
</welcome-file-list><br />
</blockquote><br />
And as for now, I put all my JSPs in the /jsp/ folder.<br />
This is my application structure:<br />
<br />
<blockquote><b>/</b> - root of application<br />
<b>/jsp/</b> - contains JSPs<br />
<b>/css/main.css</b> - contains CSS<br />
<b>/js/jsfile.js</b> - contains all of my java script code<br />
<b>/images/</b> - contains a lot of images<br />
</blockquote><br />
My task is to create a login system for this application, and to provide that only logged users , with roles “boss” or “manager” are allowed to se my JSP pages ( located in “<b>/jsp/</b>” folder )<br />
<br />
To do that, the first thing we’ll do is to define (add ) roles in our web.xml.<br />
This can be done in some other files as well, but I’ll do it here…<br />
<i>Note: These roles must be equal to those in active directory.</i><br />
<br />
So, let’s add these two roles:<br />
<br />
<blockquote><b><security-role></b><br />
<b> <role-name>boss</role-name></b><br />
<b> </security-role></b><br />
<b> <security-role></b><br />
<b> <role-name>manager</role-name></b><br />
<b></security-role></b> <br />
</blockquote><br />
Next thing we’ll do is to create a security constraint on accessing web pages:<br />
<br />
<blockquote><b><security-constraint></b><br />
<b> <web-resource-collection></b><br />
<b> <web-resource-name>Protected area</web-resource-name></b><br />
<b> <url-pattern>/*</url-pattern> </b><br />
<b> </web-resource-collection></b><br />
<br />
<b> <auth-constraint></b><br />
<b> <role-name>boss</role-name></b><br />
<b> <role-name>manager</role-name></b><br />
<b> </auth-constraint> </b><br />
<b></security-constraint></b><br />
</blockquote><br />
This way, we deny acces to our resources to anyone except to those of role “boss” or “manager”.<br />
<br />
Next thing we need to do is to define the authentication method we will be using. <br />
There are several authentication methods: BASIC, FORM-BASED , DIGEST , SECURE SOCKET LAYER ( SSL) and CLIENT CERTIFICATE AUTHENTICATION.<br />
<br />
Which one to use - depends on what exactly you need.<br />
<br />
For us, the most interesting method is FORM-BASED authentication.<br />
With this method, you create your custom JSP login form inside your application, with your own look and feel.<br />
There are 3 very important things to know when working with form-based authentication:<br />
<br />
<b>- input field containing user name must be named “j_username”<br />
- input field containing password must be named “j_password”<br />
- action for form containing these two inputs must be “j_security_check”</b><br />
<br />
So, let’s create one!<br />
Here is the example of such page,:<br />
<br />
<blockquote><b><html></b><br />
<b><head></b><br />
<b><title>Login Page for Examples</title></b><br />
<b><body bgcolor="white"></b><br />
<b><form method="POST" action="j_security_check" ></b><br />
<b> <table border="0" cellspacing="5"></b><br />
<b> <tr></b><br />
<b> <th align="right">Username:</th></b><br />
<b> <td align="left"><input type="text" name="j_username"></td></b><br />
<b> </tr></b><br />
<b> <tr></b><br />
<b> <th align="right">Password:</th></b><br />
<b> <td align="left"><input type="password" name="j_password"></td></b><br />
<b> </tr></b><br />
<b> <tr></b><br />
<b> <td align="right"><input type="submit" value="Log in"></td></b><br />
<b> <td align="left"><input type="reset"></td></b><br />
<b> </tr></b><br />
<b> </table></b><br />
<b></form></b><br />
<b></body></b><br />
<b></html></b><br />
</blockquote><br />
Let’s call it “login.jsp”, and place it in the root folder ( <b>/login.jsp</b> )<br />
<br />
Now, let’s map it inside web.xml:<br />
<br />
<blockquote><b><login-config></b><br />
<b> <auth-method>FORM</auth-method></b><br />
<b> <form-login-config></b><br />
<b> <form-login-page>/login.jsp</form-login-page></b><br />
<br />
<b> </form-login-config></b><br />
<b></login-config></b><br />
</blockquote><br />
For now, this is good, but it’s not enough. <br />
We also need to define a <i><b>form-error-page</b></i> inside a <b><form-login-config></b> tag…<br />
Application server will open that page when user enters wrong user name or password.<br />
<br />
Here is what I’m going to do:<br />
I’ll define login.jsp page to be form-error-page too, but with result=false in URL.<br />
This way we will know that we need to add some warning message to user that didn’t enter valid username and/or password.<br />
Let’s edit that prevoius <login-config>:<br />
<br />
<blockquote><b><login-config></b><br />
<b> <auth-method>FORM</auth-method></b><br />
<b> <form-login-config></b><br />
<b> <form-login-page>/login.jsp</form-login-page></b><br />
<b> <form-error-page>/login.jsp?result=false</form-error-page></b><br />
<b> </form-login-config></b><br />
<b></login-config></b><br />
</blockquote><br />
and let’s edit that login.jsp page, to show error messages when needed:<br />
<br />
<blockquote><b><html></b><br />
<b><head></b><br />
<b><title>Login Page for Examples</title></b><br />
<b><body bgcolor="white"></b><br />
<b> <%</b><br />
<b> String result = request.getParameter("result");</b><br />
<b> if(result == null)</b><br />
<b> result = "";</b><br />
<b> if (result.equalsIgnoreCase("false")) </b><br />
</blockquote><blockquote><b> {<br />
%><br />
<span style="color: red"><br />
Wrong user name or password <br />
<br><br />
</span><br />
<% </b><br />
</blockquote><blockquote><b> }</b><br />
<b> %></b><br />
<b><form method="POST" action="j_security_check" ></b><br />
<b> <table border="0" cellspacing="5"></b><br />
<b> <tr></b><br />
<b> <th align="right">Username:</th></b><br />
<b> <td align="left"><input type="text" name="j_username"></td></b><br />
<b> </tr></b><br />
<b> <tr></b><br />
<b> <th align="right">Password:</th></b><br />
<b> <td align="left"><input type="password" name="j_password"></td></b><br />
<b> </tr></b><br />
<b> <tr></b><br />
<b> <td align="right"><input type="submit" value="Log in"></td></b><br />
<b> <td align="left"><input type="reset"></td></b><br />
<b> </tr></b><br />
<b> </table></b><br />
<b></form></b><br />
<b></body></b><br />
<b></html></b><br />
</blockquote><br />
So…<br />
We created login.jsp page, we mapped it in the web.xml and earlier before we made an acces constraint to all of our folders so only logged users can access it.<br />
But now question is: “what if our login page uses some image from <b>/images/</b> folder in it, or some java script from within <b>/js/</b> , or css from within<b> /css/</b> as it probably would?”<br />
<br />
If we leave everything like this, your login form will not be able to read your css and images, and it will look very bad…<br />
<br />
What we now need to do is to make some resource public, so that our login.jsp page could use it…<br />
To do so, we could make some existing folders public ( for example /css/ and /images/ ) , or we could copy particular resources ( some images and css that login.jsp needs ) to some new folder and make public only what has to be public ( what we copied ), nothing more…<br />
We’ll do that…<br />
Let’s call this folder “<b>login_resources</b>”<br />
Let’s place it in the root:<br />
<br />
<b>/login_resources/</b><br />
<br />
Copy all the resources that you login.jsp uses to this folder.<br />
We will now create one more security constraint that will allow everyone ( login.jsp ) to access it:<br />
<br />
<blockquote><b><security-constraint></b><br />
<b> <web-resource-collection></b><br />
<b> <web-resource-name>Unprotected area</web-resource-name></b><br />
<b> <url-pattern>/login_resources/*</url-pattern></b><br />
<b> </web-resource-collection></b><br />
<b> </security-constraint></b><br />
</blockquote><br />
We intentionaly “forgot” to set <b><auth-constraint></b> inside <b><security-constraint></b> so that everyone could access this resource.<br />
<br />
Now, our login form will be able to read all the resources it needs…<br />
<br />
And, at the end, we need to add our JNDI realm to our context.xml file<br />
You could add this realm to some other files as well, but I like to add it to context.xml.<br />
<br />
Here is one example of it:<br />
<br />
<blockquote><b><Realm </b><br />
<b> className="org.apache.catalina.realm.JNDIRealm" </b><br />
<b> debug="99"</b><br />
<b> connectionURL="ldap://localhost:389"</b><br />
<b> userPattern="uid={0},ou=people,dc=mycompany,dc=com"</b><br />
<b> roleBase="ou=groups,dc=mycompany,dc=com"</b><br />
<b> roleName="cn"</b><br />
<b> roleSearch="(uniqueMember={0})"</b><br />
<b>/></b><br />
</blockquote><br />
Please, visit <a href="http://tomcat.apache.org/tomcat-6.0-doc/realm-howto.html">http://tomcat.apache.org/tomcat-6.0-doc/realm-howto.html</a> for more information on creating realms.<br />
Place this realm inside <b><context></b> <b></context></b> tag in context.xml file.<br />
<br />
So, let’s sumarize:<br />
<br />
Our web.xml now looks like this:<br />
<br />
<blockquote><b><?xml version="1.0" encoding="UTF-8"?></b><br />
<b><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"></b><br />
<br />
<b> <filter></b><br />
<b> <filter-name>struts2</filter-name></b><br />
<b> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class></b><br />
<b> </filter></b><br />
<b> <filter-mapping></b><br />
<b> <filter-name>struts2</filter-name></b><br />
<b> <url-pattern>/*</url-pattern></b><br />
<b> </filter-mapping></b><br />
</blockquote><br />
<blockquote><b> <session-config></b><br />
<b> <session-timeout></b><br />
<b> 15</b><br />
<b> </session-timeout></b><br />
<b> </session-config></b><br />
</blockquote><br />
<blockquote><b> <welcome-file-list></b><br />
<b> <welcome-file>index.jsp</welcome-file></b><br />
<b> </welcome-file-list></b><br />
<br />
<b><security-role></b><br />
<b> <role-name>boss</role-name></b><br />
<b> </security-role></b><br />
<b> <security-role></b><br />
<b> <role-name>manager</role-name></b><br />
<b></security-role> </b><br />
<br />
<b><security-constraint></b><br />
<b> <web-resource-collection></b><br />
<b> <web-resource-name>Protected area</web-resource-name></b><br />
<b> <url-pattern>/*</url-pattern> </b><br />
<b> </web-resource-collection></b><br />
<br />
<b> <auth-constraint></b><br />
<b> <role-name>boss</role-name></b><br />
<b> <role-name>manager</role-name></b><br />
<b> </auth-constraint> </b><br />
<b></security-constraint></b><br />
<br />
<b><security-constraint></b><br />
<b> <web-resource-collection></b><br />
<b> <web-resource-name>Unprotected area</web-resource-name></b><br />
<b> <url-pattern>/login_resources/*</url-pattern></b><br />
<b> </web-resource-collection></b><br />
<b> </security-constraint></b><br />
</blockquote><br />
<blockquote><b><login-config></b><br />
<b> <auth-method>FORM</auth-method></b><br />
<b> <form-login-config></b><br />
<b> <form-login-page>/login.jsp</form-login-page></b><br />
<b> <form-error-page>/login.jsp?result=false</form-error-page></b><br />
<b> </form-login-config></b><br />
<b></login-config></b><br />
</blockquote><br />
<br />
Once the user logs in, application server will create a session for him.<br />
You can access it’s user name with <br />
<br />
<b>ServletActionContext.getRequest().getUserPrincipal().getName();</b><br />
<br />
or check if he has a sufficient role with<br />
<br />
<b>ServletActionContext.getRequest().isUserInRole(“some_role”);</b><br />
<br />
<br />
And if you would like to logout, you can use <br />
<br />
<b>getRequest().getSession().invalidate();</b><br />
<br />
<br />
<br />
<br />
<br />
That’s it for now…<br />
I hope I helped someone and saved him some time...Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com6tag:blogger.com,1999:blog-2760857886315929363.post-59144387236298282642009-09-22T02:40:00.000-07:002010-01-21T06:16:08.675-08:00Using simple theme and custom CSS in Struts2Simple theme in Struts2 is great when you want to use your own CSS , and control everything by yourself when it comes to GUI.<br />
Probably many of you (us :-) ) tried using Struts2 with your own CSS without setting default theme to SIMPLE and came up with bunch of unfamiliar tags , like<br />
<br />
<b><table class="wwFormTable"></b><br />
<br />
In your HTML…<br />
<br />
Well , if you want to use your own CSS and get your application to look like you wanted to, you need to either create your own new theme ( harder ), or just use Simple theme and use your own CSS ( easier ).<br />
<br />
In order to switch to simple theme, just copy/paste this line to your struts.properties file:<br />
<br />
<blockquote>struts.ui.theme=simple<br />
</blockquote><br />
<br />
Visit<br />
<a href="http://draft.blogger.com/%20http://devtalks.blogspot.com/2009/07/create-struts2-project-in-netbeans.html"> http://devtalks.blogspot.com/2009/07/create-struts2-project-in-netbeans.html</a><br />
if you are using NetBeans , or<br />
<br />
<a href="http://devtalks.blogspot.com/2009/07/eclipse-galileo-and-struts2.html%20">http://devtalks.blogspot.com/2009/07/eclipse-galileo-and-struts2.html </a><br />
if you are using eclipse<br />
<br />
on how to create Struts2 project , and struts.properties file<br />
<br />
And that’s it! This way your pages will not contain those annoying<br />
<b><table class="wwFormTable"></b> tags…<br />
<br />
<br />
<b style="color: #666666;"><i>ISSUES</i></b><br />
<br />
One thing I noticed when using simple theme is that struts tag <b><s:fielderror></b> doesn’t seems to “work” as it should…<br />
You cannot just say, for example,<br />
<br />
<blockquote><b><s:fielderror /></b><br />
<b><s:textfield name=”firstName” /></b><br />
</blockquote><br />
and expect from struts2 to show errors if your validator doesn’t succeed in validating filed “firstName” .<br />
As a matter of fact, struts2 will indeed dispatch to your INPUT result, but it will not show any errors!<br />
Fortunately , There is a solution to this problem: just use<br />
<br />
<b><s:fielderror> <s:param>filed_name</s:param> </s:fielderror> </b><br />
instead of<br />
<b><s:fielderror /></b><br />
<br />
in your .jsp pages and your validation will again act as it should…<br />
<br />
<br />
<b><i><span style="color: #666666;">ALTERING FieldErrors , ActionMessages and ActionErrors</span> </i></b><br />
<br />
Speaking of fielderrors, I often see people asking how to change the way Struts is showing field errors action messages and action errors…<br />
<br />
You do this by extending the theme you are using. When using simple theme, all you need to do is:<br />
<br />
- Create subfolders “template” and “simple” inside folder “classes”<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtwb3PltZPqMSgx5nel7NhP6AoQeEY5Xw3sukp693H5HVDVinWMp2qZpJjB-aI-qNKy7q_TCDuNhjz2uTBx9Yw6c-K0Dc8krljQ0dxvrYxqPGAnY21fN868xwAGtC5QoBQ9jcNupln6uI/s1600-h/0.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtwb3PltZPqMSgx5nel7NhP6AoQeEY5Xw3sukp693H5HVDVinWMp2qZpJjB-aI-qNKy7q_TCDuNhjz2uTBx9Yw6c-K0Dc8krljQ0dxvrYxqPGAnY21fN868xwAGtC5QoBQ9jcNupln6uI/s400/0.gif" /></a><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">- Find actionerror.ftl , actionmessage.ftl and fielerror.ftl ( or just those which you would like to extend ) in struts2-core-2.x.x.jar , inside “template.simple” package. You can find this .JAR inside your “libraries” folder.<br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj60qeBCBp6mYhX8zp676RgxxSqNU3-YDl48KZGAEV-0VTbbIsWxyngIKFvWMsYkEU7SmRmYbJFlOADalmOp-Wc_YlPM2Ym3IrX_n9hUNU50IGx7uH5qRvsu7kYVClR47yz8NzXSXUDWHA/s1600-h/2.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj60qeBCBp6mYhX8zp676RgxxSqNU3-YDl48KZGAEV-0VTbbIsWxyngIKFvWMsYkEU7SmRmYbJFlOADalmOp-Wc_YlPM2Ym3IrX_n9hUNU50IGx7uH5qRvsu7kYVClR47yz8NzXSXUDWHA/s400/2.gif" /></a><br />
<div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">- Copy these files to your new template -> simple folder created in earlier step.<br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMcCIPLXOThJFYzFeLQYy8KburhiKwDQvgV4grtn6YPBTrRzg8c9FVS-gU1juOKGp65FIkLO01V3XlcYP82etdBSmphyZUJjIQCHzOOp4_IDZ_YaWx5PnZO9S728NrB7V2NZcTvylkV5k/s1600-h/1.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMcCIPLXOThJFYzFeLQYy8KburhiKwDQvgV4grtn6YPBTrRzg8c9FVS-gU1juOKGp65FIkLO01V3XlcYP82etdBSmphyZUJjIQCHzOOp4_IDZ_YaWx5PnZO9S728NrB7V2NZcTvylkV5k/s400/1.gif" /></a><br />
<div class="separator" style="clear: both; text-align: center;"><br />
</div>If you open one of these files, you’ll see how these messages are generated.<br />
You can change all that just by editing that file.<br />
<br />
Lets say you don’t want your application to show fielderrors as <ul> <li> </li> <ul> elements.<br />
You just need to open the fielderror.ftl and change the part that does this:<br />
<br />
So, instead of having<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj26lzxvFn-_GvtacRxUl2VAFxK7vpUGDcIwcGK1s2EWpt15BfmgUsGsTDShssVVSCUmzf8DLKW_Ol6Rlyyr9gxGaAEZZx0Rdbiiee0FLH4w0vrgHRU3enps0QzSrGcsmM8ytTI8B1UEbg/s1600-h/ef1.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj26lzxvFn-_GvtacRxUl2VAFxK7vpUGDcIwcGK1s2EWpt15BfmgUsGsTDShssVVSCUmzf8DLKW_Ol6Rlyyr9gxGaAEZZx0Rdbiiee0FLH4w0vrgHRU3enps0QzSrGcsmM8ytTI8B1UEbg/s400/ef1.gif" /></a><br />
</div><div class="separator" style="clear: both; text-align: left;">like it is in original file, we can just remove <ul> <li> </li> <ul> elements, and change it with, for example, simple <span> </span> element. That will do the trick. ;-)<br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDgrOeeb1Aod82EGIZ7LC8aAsXV39i6lCIi9PUIA3mpTbChPY9ikV3BHZxDBXXj8fQGzRNNi0E7QjJT1JlZQsB-BEHUxxzWJICCVHMoshGy-ao7meyH6l0g40P7Aa4Og37-etiqWPsrRc/s1600-h/ef2.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDgrOeeb1Aod82EGIZ7LC8aAsXV39i6lCIi9PUIA3mpTbChPY9ikV3BHZxDBXXj8fQGzRNNi0E7QjJT1JlZQsB-BEHUxxzWJICCVHMoshGy-ao7meyH6l0g40P7Aa4Og37-etiqWPsrRc/s400/ef2.gif" /></a><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">Or let’s, for example,change the way your Action message is shown in an application.<br />
</div>Let’s say we need a green box with all the action messages shown in it…<br />
Something like this:<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTlYOzHrln5TkK8N-aj6nAA0DspFEm2FOp6VrfjcR0ll0jZd8J0eZrSn7kEPARGGttc0NiJ7TFj1iehpfZUYEzQW21BUaWb5FzQgmc919869Z_l_juX_P2l40YXksq98zGVbZ03LbEL5c/s1600-h/3.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTlYOzHrln5TkK8N-aj6nAA0DspFEm2FOp6VrfjcR0ll0jZd8J0eZrSn7kEPARGGttc0NiJ7TFj1iehpfZUYEzQW21BUaWb5FzQgmc919869Z_l_juX_P2l40YXksq98zGVbZ03LbEL5c/s320/3.gif" /></a><br />
</div><div class="separator" style="clear: both; text-align: left;">To do this, you could just open the actionmessage.ftl file, and change the original<br />
</div><br />
<blockquote><b><#if (actionMessages?? && actionMessages?size > 0)></b><br />
<b> <ul<#rt/></b><br />
<b><#if parameters.cssClass??></b><br />
<b> class="${parameters.cssClass?html}"<#rt/></b><br />
<b><#else></b><br />
<b> class="actionMessage"<#rt/></b><br />
<b></#if></b><br />
<b><#if parameters.cssStyle??></b><br />
<b> style="${parameters.cssStyle?html}"<#rt/></b><br />
<b></#if></b><br />
<b>></b><br />
<b> <#list actionMessages as message></b><br />
<b> <li><span>${message!}</span></li></b><br />
<b> </#list></b><br />
<b> </ul></b><br />
<b></#if></b><br />
</blockquote><div class="separator" style="clear: both; text-align: left;"><br />
</div><br />
with something like this:<br />
<br />
<br />
<blockquote><b><#if (actionMessages?? && actionMessages?size > 0)></b><br />
<b> <div class="mymessage"><br><span<#rt/></b><br />
<b><#if parameters.cssClass??></b><br />
<b> class="${parameters.cssClass?html}"<#rt/></b><br />
<b><#else></b><br />
<b> class="actionMessage"<#rt/></b><br />
<b></#if></b><br />
<b><#if parameters.cssStyle??></b><br />
<b> style="${parameters.cssStyle?html}"<#rt/></b><br />
<b></#if></b><br />
<b>></b><br />
<b> <#list actionMessages as message></b><br />
<b> <span>- ${message!}</span></b><br />
<b> </#list></b><br />
<b> </span><br><br></div></b><br />
<b></#if></b><br />
</blockquote><div class="separator" style="clear: both; text-align: left;"><br />
</div>And for now on, every Action message in your application will look like a green box containing messages.<br />
<br />
Here is the css I used:<br />
<br />
<b>div.mymessage<br />
{<br />
right: 0;<br />
bottom: 0;<br />
left: 0;<br />
width:300px;<br />
margin: auto;<br />
color: #33CC33;<br />
border-color:#009900;<br />
border-style:solid ;<br />
border-width:1px;<br />
border-collapse: collapse;<br />
font-weight: bold;<br />
text-align: center;<br />
background-color:#DDFFDD;<br />
}</b><br />
<br />
This is just a simple example what you can do with extending a theme...<br />
<br />
<div style="text-align: center;"><br />
</div>Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com10tag:blogger.com,1999:blog-2760857886315929363.post-56148417806575520732009-08-16T07:33:00.000-07:002010-01-21T06:22:03.086-08:00Stigla majica sa Eclipse Galileo Blogathon-aI ove godine sam se odazvao <a href="http://www.eclipse.org/galileo/blogathon/guidelines.php">pozivu</a> Eclipse fondacije da se napiše blog povodom izlaska nove verzije Eclipse-a<b> </b>pod nazivom "Galileo".<br />
<br />
<a href="http://devtalks.blogspot.com/2009/07/eclipse-galileo-and-struts2.html">Link</a> na post. <br />
<br />
I ove godine sam,naravno, na moju veliku radost dobio od fondacije majicu sa logom Eclipse-a.<br />
Šta reći o majici? Zaista je super!<br />
<br />
Evo sličica:<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnf49-TWi9FuAt_alkbs3hh-0rr5d5gCMu-ys5jBE7hTKnNmrHEvHXdiRbkPyNfQH_6KEEKowM-eG57w9GL-Cr9iqh7jeyV7uDGW0jNdkQKNDGsgj5KLYNF6-nqF4w3JiqvA4bx1OHg8I/s1600-h/ja.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnf49-TWi9FuAt_alkbs3hh-0rr5d5gCMu-ys5jBE7hTKnNmrHEvHXdiRbkPyNfQH_6KEEKowM-eG57w9GL-Cr9iqh7jeyV7uDGW0jNdkQKNDGsgj5KLYNF6-nqF4w3JiqvA4bx1OHg8I/s320/ja.gif" /></a><br />
</div>Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com0tag:blogger.com,1999:blog-2760857886315929363.post-26472996961105388722009-08-09T07:11:00.000-07:002010-01-21T06:17:10.858-08:00Create and use an oracle connection pool in Tomcat 6.xx<b>NOTE:</b> <i><b>this post is in fact a translation and a shorter version of <a href="http://www.baze-podataka.net/2009/08/04/kreiranje-connection-pool-a-za-oracle-na-tomcat-6-app-serveru/">post</a> that I wrote on my other blog ( www.baze-podataka.net ). It is translated using <a href="http://translate.google.com/#">Google translate</a> tool and than slightly modified by me. So, if you have any complaints, please complain to <a href="http://www.google.com/">Google</a> ;-)</b></i><br />
<br />
Creating a connection pool is a very good practice when developing applications that often connect to the database because it is much "cheaper" to use one of the already created connections, then to repeat the entire process of Connecting to the database every time we need a connection.<br />
It’s such a good practice that many application servers already have their own implementation of connection pooling.<br />
<br />
Such server is Tomcat.<br />
<br />
All that is left for us to do, of course, is to set all the properties of server that we need to use, and to provide the appropriate drivers that work with a specific database.<br />
Then, if necessary, just take the connection from the pool, and use it, but take care of their proper use.<br />
<br />
In this post, I will set Tomcat 6.0.18.<br />
A database for which I’ll create a connection pool is Oracle 10g.<br />
<br />
There’s a lot of tutorials, texts and examples about this on the Internet, but very often related to older versions of Tomcat (ver. 4, 5, 5.5).<br />
Unfortunately, for all of these earlier versions of Tomcat many specifications and settings are different, so it probably won’t work with version 6.xx. At least that was the case with me.<br />
<br />
So, let’s create an oracle connection pool!<br />
<br />
<b>Prerequisites: </b><br />
First thing you need to have is , of course, Tomcat.<br />
You can download it following <a href="http://tomcat.apache.org/download-60.cgi">this</a> link.<br />
If you use NetBeans to write a code, as I do, you can use Tomcat that comes bundled with the installation of the IDE itself.<br />
<br />
Next, we need the appropriate JDBC drivers for Oracle 10g. This means you need an <span style="font-weight: bold;">ojdbc14.jar</span> file that comes within the Oracle itself.<br />
<br />
Copy this file to <b><Tomcat home dir>/lib/</b> folder.<br />
<br />
And, of course, we need a database installed too.<br />
Check whether the database you wish to use is available and whether you can connect to it.<br />
<br />
<b>create a connection pool </b><br />
<br />
Creating the pool is a quite fast and easy job.<br />
For example, if your application context path is <span style="font-weight: bold;">/myapp</span> , it is necessary for you to:<br />
<br />
1. Edit the <span style="font-weight: bold;">context.xml</span> file, which is located within the META-INF folder of your project like this:<br />
<br />
<blockquote><?xml version=”1.0? encoding=”UTF-8??><br />
<Context path=”/myapp” docBase=”myapp” reloadable=”false”><br />
<Resource name=”jdbc/oracleconnection” auth=”Container”<br />
type=”javax.sql.DataSource” username=”existing_username” password=”user_password”<br />
driverClassName=”oracle.jdbc.driver.OracleDriver” url=”jdbc:oracle:thin:@xxx.xxx.xxx.xxx:1521:sid”<br />
maxActive=”10? maxIdle=”5?/><br />
</Context><br />
</blockquote><br />
<br />
By setting these parameters you determine how this pool will “look” like.<br />
Visit Tomcat’s website for a list of all available parameters.<br />
<br />
2. In the <span style="font-weight: bold;">web.xml</span> file of your application, you need to insert:<br />
<br />
<blockquote><resource-ref><br />
<res-ref-name>jdbc/oracleconnection</res-ref-name><br />
<res-type>javax.sql.DataSource</res-type><br />
<res-auth>Container</res-auth><br />
</resource-ref><br />
</blockquote>inside tags <web-app> and </web-app><br />
<br />
And that's it!<br />
Of course, this is not the only way to create connection pool in Tomcat-6, but it is quite simple, don't you think?<br />
<br />
<b>Hot to use connections within our web applications </b><br />
<br />
Using connection pool’s connections within our web applications is as easy as creating the pool itself.<br />
<br />
In Java EE, DataSource objects are obtained using the JNDI lookup mechanism.<br />
All you need to do to get a connection is something like this:<br />
<br />
<blockquote>Connection connection = null;<br />
InitCtx context = new InitialContext ();<br />
EnvCtx context = (Context) initCtx.lookup ( "java:comp/ENV");<br />
DataSource ds = (DataSource) envCtx.lookup ("JDBC/oracleconnection");<br />
connection = ds.getConnection ();<br />
</blockquote><br />
and that’s it.<br />
<br />
If you are interested in learning more about connection pool, and the best ways of using it, I suggest you to visit my earlier <a href="http://devtalks.blogspot.com/2009/06/struts-2-design-and-programming.html">post</a> , and read the 11th chapter of the book I wrote about...Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com3tag:blogger.com,1999:blog-2760857886315929363.post-63737865172715653192009-07-29T05:47:00.000-07:002010-01-21T06:18:08.659-08:00Eclipse Galileo and Struts2I was quite surprised with how many people came to my blog and read my <a href="http://devtalks.blogspot.com/2009/07/create-struts2-project-in-netbeans.html">earlier</a> post on how to create a blank Struts2 project and start using this framework in NetBeans 6.5<br />
<br />
With a release of new Eclipse, I thought it would be interesting to do the same thing, but now in this IDE.<br />
As you probably already know, Eclipse is one of the famous and certainly one of the best Java IDEs.<br />
Well, about a month ago people from Eclipse foundation released a 3.5 version of Eclipse, called <b>Galileo</b>.<br />
<br />
I develop almost all my project using NetBeans, and have never done any Struts2 programming using Eclipse.<br />
That is why I decided to write a post on how to create a Struts2 example in new Eclipse release: Galileo. That's quite fun because that way I (we) get to learn on how to use Struts2 in Eclipse, and get to see Galileo in action a little bit closer…<br />
<span style="font-size: 85%;"><br />
<span style="font-style: italic;">Note: In this post, I’ll use much of the text , entire source code and application logic from my previous post and concetrate only on the differences between these two IDEs. </span></span><br />
<br />
So, let’s get started:<br />
<br />
First of all we need Eclipse Galileo. Go to the <a href="http://www.eclipse.org/downloads/">http://www.eclipse.org/downloads/</a> and download Eclipse IDE for Java EE Developers.<br />
<br />
Next thing we need is Struts2 itself. Go to <a href="http://struts.apache.org/2.x/index.html">http://struts.apache.org/2.x/index.html</a> and download the latest version of Struts2.<br />
I downloaded struts-2.1.6-all.zip<br />
You won't be needing all the libraries in it. Just 6 of them. Because of this, you can download essential dependencies only.<br />
<br />
When you download one of these archives, extract it to some location, for example: c:\Struts2<br />
<br />
It is now time to start a new project. Start Eclipse Galileo.<br />
<br />
<br />
Click file --> new --> Dynamic web project<br />
<br />
<br />
<br />
Let’s call this project <b>GalileoStruts2Example</b><br />
I’ll use Tomcat 6 . You can use some other server that you have available , it is completely up to you.<br />
<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEid6-61Un7OOXlaUZI-o8Aq91diH78yKW1UZBPRR5uQmPMjXA9b6G5B7PZgL8um0HH8-r_-E_V2jdAY_aFeTpwMwe9WRn8laX9CH1KFiQo7dzRebe6U1BIn5rynk6dnSe19q5DEHoB0BfM/s1600-h/1.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEid6-61Un7OOXlaUZI-o8Aq91diH78yKW1UZBPRR5uQmPMjXA9b6G5B7PZgL8um0HH8-r_-E_V2jdAY_aFeTpwMwe9WRn8laX9CH1KFiQo7dzRebe6U1BIn5rynk6dnSe19q5DEHoB0BfM/s400/1.gif" /></a><br />
</div><div style="text-align: center;"><br />
</div><div style="text-align: center;"><br />
</div><div style="text-align: center;"><div style="text-align: left;">Click Finish.<br />
<br />
Your project tree will look like this:<br />
</div><div style="text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjduYL2On59X6pG8SWmFMHsP485wPomUuJnf6nvLvex6j6Y5DCnNKA7Y7YWOM0Pa_c_l7LJ86O5kzQ62j6KUjivAXPqwyp_LeG137ES6DpEfY-WzWebfw7R6sd0dbPTfXRTEQcNtESrNq8/s1600-h/2.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjduYL2On59X6pG8SWmFMHsP485wPomUuJnf6nvLvex6j6Y5DCnNKA7Y7YWOM0Pa_c_l7LJ86O5kzQ62j6KUjivAXPqwyp_LeG137ES6DpEfY-WzWebfw7R6sd0dbPTfXRTEQcNtESrNq8/s400/2.gif" /></a><br />
</div><div style="text-align: center;"><br />
</div><div style="text-align: left;">Now, in order to use Struts2 libraries, let's add those essential dependencies to project:<br />
<br />
Right-click on the project --> properties --> Java Build Path , select Libraries tab and click on the “Add External JARs” button.<br />
<br />
Go to folder where you extracted Struts2 libraries and select ( add to project ) following files:<br />
<br />
<b>- struts2-core-2.1.6.jar<br />
- freemarker-2.3.13.jar<br />
- ognl-2.6.11.jar<br />
- commons-fileupload-1.2.1.jar<br />
- commons-logging-1.0.4.jar<br />
- xwork-2.1.2.jar</b><br />
<br />
Most of the tutorials on the web are written for older version of struts2, at the time when <b>commons-fileupload-1.2.1.jar</b> was not mandatory, so even when following all the steps in tutorial , you just couldn't get your project to work ( with newer version of Struts2 ) !<br />
<br />
Now, your project will look like this:<br />
</div><div style="text-align: left;"></div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOtkJgMKo3KZcIYCvzS749vJbzKqgl2d5XwqfAuqreE_Ad2iMJvmVgWznAHVtrzqh_09laot1NUiDGDQ_EShTBJ87Tze-paRGAjRyER0LV1LMMyuwd5Gxuy-UCkvJuJM5u0LVHIlUZI38/s1600-h/3.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOtkJgMKo3KZcIYCvzS749vJbzKqgl2d5XwqfAuqreE_Ad2iMJvmVgWznAHVtrzqh_09laot1NUiDGDQ_EShTBJ87Tze-paRGAjRyER0LV1LMMyuwd5Gxuy-UCkvJuJM5u0LVHIlUZI38/s400/3.gif" /></a><br />
</div></div><div style="text-align: center;"><div style="text-align: left;"></div><div style="text-align: left;">Now, copy these six JARs into the “lib” folder located in the root of WEB-INF folder.<br />
</div><div style="text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXI1vzF4U-pwYJyZPFjqfE6m9gzrRTnLZvQUkNwRzTPKLG1gQBXDKgnCwrH-GgfJJIjxDKYW24vb61RE26IlUOEw6Tt5btkDhgqzj0ji6EuF1myYErkaB39mDk_3VGgsEZMu93G43gTzY/s1600-h/4.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXI1vzF4U-pwYJyZPFjqfE6m9gzrRTnLZvQUkNwRzTPKLG1gQBXDKgnCwrH-GgfJJIjxDKYW24vb61RE26IlUOEw6Tt5btkDhgqzj0ji6EuF1myYErkaB39mDk_3VGgsEZMu93G43gTzY/s320/4.gif" width="320" /></a><br />
</div><div style="text-align: left;"><br />
</div><br />
<div style="text-align: left;">These files will be uploaded to App Server , and a deployed application will use it.<br />
We could put this files into main lib folder of application server, but it is most probably better this way...<br />
<br />
We need to create one more folder in the root of the WEB-INF , and name it "classes".<br />
This is where you will create <b>struts.xml</b>, and if needed - a <b>struts.properties</b> file.<br />
<br />
I'll put all my JSP's into new folder, "jsp" , which I will create in the root of "WebContent" folder.<br />
<br />
All Java code that we write, we will place into some package in the "Java Resources: src" folder.<br />
I'll create one now, called "struts2Example" and a "Hello" Class in it.<br />
If you use validaton, put all Validation XMLs inside class's package too...<br />
</div><div style="text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5qEdchPUx35XrIVmwEHbPN5cC2FWvYUIYlQUdwxvuC62VmIb05WLqXARerM0KqMGtEOrKCsTyNk2McWNwP35NEqBm2jc3Yw2TDprD6GwYPLWT9aKSOPnD7pWLD860DRQx1USpOFIhIWs/s1600-h/5.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5qEdchPUx35XrIVmwEHbPN5cC2FWvYUIYlQUdwxvuC62VmIb05WLqXARerM0KqMGtEOrKCsTyNk2McWNwP35NEqBm2jc3Yw2TDprD6GwYPLWT9aKSOPnD7pWLD860DRQx1USpOFIhIWs/s400/5.gif" /></a><br />
</div><div style="text-align: left;"><br />
</div><br />
<div style="text-align: left;">This is how, at minimum, your Struts2 project structure should look like.<br />
<br />
<br />
I'll create one small Struts2 application now. Nothing complicated.<br />
User will enter his name, and press "submit" and other page will open , saying Hello to this user.<br />
<br />
So, let's first create a Java class extending ActionSupport class , named Hello, inside Struts2Example package.<br />
Let's make it to look something like this:<br />
</div><div style="text-align: left;"><br />
</div><div style="text-align: center;"><div style="text-align: left;"></div><blockquote><div class="MsoNormal" style="text-align: left;"><b><span style="color: #7f0055; font-family: Arial;">package</span></b><span style="color: black; font-family: Arial;"> struts2Example;</span><span style="font-family: Arial;"><o:p></o:p></span><br />
</div><div></div><div class="MsoNormal" style="text-align: left;"></div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"><b><span style="color: #7f0055; font-family: Arial;">import</span></b><span style="color: black; font-family: Arial;"> com.opensymphony.xwork2.ActionSupport;</span><span style="font-family: Arial;"><o:p></o:p></span><br />
</div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"></div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"><br />
<span style="font-family: Arial;"><o:p></o:p></span><br />
</div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"><b><span style="color: #7f0055; font-family: Arial;">public</span></b><span style="color: black; font-family: Arial;"> </span><b><span style="color: #7f0055; font-family: Arial;">class</span></b><span style="color: black; font-family: Arial;"> Hello </span><b><span style="color: #7f0055; font-family: Arial;">extends</span></b><span style="color: black; font-family: Arial;"> ActionSupport</span><span style="font-family: Arial;"><o:p></o:p></span><br />
</div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"><span style="color: black; font-family: Arial;">{</span><span style="font-family: Arial;"><o:p></o:p></span><br />
</div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"><span style="color: black; font-family: Arial;"> </span><b><span style="color: #7f0055; font-family: Arial;">private</span></b><span style="color: black; font-family: Arial;"> String </span><span style="color: #0000c0; font-family: Arial;">name</span><span style="color: black; font-family: Arial;">, </span><span style="color: #0000c0; font-family: Arial;">message</span><span style="color: black; font-family: Arial;">;</span><span style="font-family: Arial;"><o:p></o:p></span><br />
</div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"></div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"><span style="color: black; font-family: Arial;"> </span><b><span style="color: #7f0055; font-family: Arial;">public</span></b><span style="color: black; font-family: Arial;"> String getName() {</span><span style="font-family: Arial;"><o:p></o:p></span><br />
</div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"><span style="color: black; font-family: Arial;"> </span><b><span style="color: #7f0055; font-family: Arial;">return</span></b><span style="color: black; font-family: Arial;"> </span><span style="color: #0000c0; font-family: Arial;">name</span><span style="color: black; font-family: Arial;">;</span><span style="font-family: Arial;"><o:p></o:p></span><br />
</div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"><span style="color: black; font-family: Arial;"> }</span><span style="font-family: Arial;"><o:p></o:p></span><br />
</div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"></div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"><span style="color: black; font-family: Arial;"> </span><b><span style="color: #7f0055; font-family: Arial;">public</span></b><span style="color: black; font-family: Arial;"> </span><b><span style="color: #7f0055; font-family: Arial;">void</span></b><span style="color: black; font-family: Arial;"> setName(String name) {</span><span style="font-family: Arial;"><o:p></o:p></span><br />
</div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"><span style="color: black; font-family: Arial;"> </span><b><span style="color: #7f0055; font-family: Arial;">this</span></b><span style="color: black; font-family: Arial;">.</span><span style="color: #0000c0; font-family: Arial;">name</span><span style="color: black; font-family: Arial;"> = name;</span><span style="font-family: Arial;"><o:p></o:p></span><br />
</div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"><span style="color: black; font-family: Arial;"> }</span><span style="font-family: Arial;"><o:p></o:p></span><br />
</div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"></div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"><span style="color: black; font-family: Arial;"> </span><b><span style="color: #7f0055; font-family: Arial;">public</span></b><span style="color: black; font-family: Arial;"> String getMessage() {</span><span style="font-family: Arial;"><o:p></o:p></span><br />
</div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"><span style="color: black; font-family: Arial;"> </span><b><span style="color: #7f0055; font-family: Arial;">return</span></b><span style="color: black; font-family: Arial;"> </span><span style="color: #2a00ff; font-family: Arial;">"Hello "</span><span style="color: black; font-family: Arial;"> + getName();</span><span style="font-family: Arial;"><o:p></o:p></span><br />
</div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"><span style="color: black; font-family: Arial;"> }</span><span style="font-family: Arial;"><o:p></o:p></span><br />
</div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"></div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"><span style="color: black; font-family: Arial;"> </span><b><span style="color: #7f0055; font-family: Arial;">public</span></b><span style="color: black; font-family: Arial;"> </span><b><span style="color: #7f0055; font-family: Arial;">void</span></b><span style="color: black; font-family: Arial;"> setMessage(String message) {</span><span style="font-family: Arial;"><o:p></o:p></span><br />
</div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"><span style="color: black; font-family: Arial;"> </span><b><span style="color: #7f0055; font-family: Arial;">this</span></b><span style="color: black; font-family: Arial;">.</span><span style="color: #0000c0; font-family: Arial;">message</span><span style="color: black; font-family: Arial;"> = message;</span><span style="font-family: Arial;"><o:p></o:p></span><br />
</div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"><span style="color: black; font-family: Arial;"> }</span><span style="font-family: Arial;"><o:p></o:p></span><br />
</div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"></div><div style="text-align: left;"></div><div class="MsoNormal" style="text-align: left;"><span style="color: black; font-family: Arial;">}</span><br />
</div></blockquote><br />
<div style="text-align: left;">We now need two JSPs, for example "nameinput.jsp" and a "response.jsp"<br />
Each JSP needs to contain this line, in order to use struts2 custom tags in it:<br />
<br />
<b><%@ taglib prefix="s" uri="/struts-tags" %></b><br />
<br />
nameinput.jsp:<br />
</div><div style="text-align: left;"></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjylCic1KlobJ5wXDAHZvEp9pxb-C-WF8h4HvYwcnsKrdYxWr1LSt8a29cmZ9rKq289ZjAwXLqpo26AMjVifJDw9n5cqFVBikrhHZh5MONcDgj6zRcNC8sVZOw2xbE-crbIBwAZrEDbo8k/s1600-h/6.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjylCic1KlobJ5wXDAHZvEp9pxb-C-WF8h4HvYwcnsKrdYxWr1LSt8a29cmZ9rKq289ZjAwXLqpo26AMjVifJDw9n5cqFVBikrhHZh5MONcDgj6zRcNC8sVZOw2xbE-crbIBwAZrEDbo8k/s400/6.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">response.jsp:<br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhChykwFpgDWxlc0T5HC3tzAx2_M18sMlJLRCR-u_mj1RuhPa0QmQjSOMg1ZZaUU-K5nAy_PfR3r6Wg4S0KhtvIde4Wee0XkSYu1AV1zkZdoGL05Nx2T8vcX8bogNhaUKTNeY_HF6Ahth4/s1600-h/7.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhChykwFpgDWxlc0T5HC3tzAx2_M18sMlJLRCR-u_mj1RuhPa0QmQjSOMg1ZZaUU-K5nAy_PfR3r6Wg4S0KhtvIde4Wee0XkSYu1AV1zkZdoGL05Nx2T8vcX8bogNhaUKTNeY_HF6Ahth4/s400/7.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">Let's create an XML validation file for Hello class, and make a name property mandatory.<br />
</div><br />
Hello-validation.xml:<br />
<br />
<b><!DOCTYPE validators PUBLIC<br />
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"<br />
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"><br />
<br />
<validators><br />
<field name="name"><br />
<field-validator type="requiredstring"><br />
<param name="trim">true</param><br />
<message>Please enter name</message><br />
</field-validator><br />
</field><br />
</validators></b><br />
<br />
Let’s see how our project tree looks at this stage:<br />
<div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2f2gWrnHJ_yQV9jrXXYLjKu4isVR8Fs1Z0NbJZC0uTBXUVp67x04qrNZgYGCL6XaG7KwpbqaBZzDxPMoPVAbTZ4sJOpz_kXMd4c53khYwDkbh0ozlEp8fUFW0p4hWrZ-wTdumUQIKh0E/s1600-h/8.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2f2gWrnHJ_yQV9jrXXYLjKu4isVR8Fs1Z0NbJZC0uTBXUVp67x04qrNZgYGCL6XaG7KwpbqaBZzDxPMoPVAbTZ4sJOpz_kXMd4c53khYwDkbh0ozlEp8fUFW0p4hWrZ-wTdumUQIKh0E/s400/8.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">There's only 2 things left for us to do:<br />
</div><br />
Edit struts.xml, and web.xml:<br />
<br />
struts.xml must be located in “classes” folder located in the root of WEB-INF folder:<br />
<div class="separator" style="clear: both; text-align: left;"><br />
</div><div style="text-align: center;"></div><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYrtwCYo-YZIy-Llzj4aBqMWkAoD739JbOnOwPedYbIhCFGIv_lq7IkIluaxKVOPTUVv-BaD89dkVMJVQphwnYNM5lzbp5-Ni07Jnt-KwVxPh9cJN_YwmVPRN_GcCWmrKYzdEcSlKl5II/s1600-h/9.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYrtwCYo-YZIy-Llzj4aBqMWkAoD739JbOnOwPedYbIhCFGIv_lq7IkIluaxKVOPTUVv-BaD89dkVMJVQphwnYNM5lzbp5-Ni07Jnt-KwVxPh9cJN_YwmVPRN_GcCWmrKYzdEcSlKl5II/s400/9.gif" /></a><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div style="text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhABIgp62j1ZGCu8B1Vbxd6ac3am_9RPdz-zfEwfhjaVSkanult35BvD6G7G01rtIVzSa-uGL_3TESFkKlPOO06OOBIqzzVRg4zwi3WWLzcfcNFgnz7ez-YcHE7F4NPK5fqpcLYz59Xzes/s1600-h/10.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhABIgp62j1ZGCu8B1Vbxd6ac3am_9RPdz-zfEwfhjaVSkanult35BvD6G7G01rtIVzSa-uGL_3TESFkKlPOO06OOBIqzzVRg4zwi3WWLzcfcNFgnz7ez-YcHE7F4NPK5fqpcLYz59Xzes/s400/10.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">This is where place a file <b>struts.properties</b> if we need to use it, as well…<br />
</div><br />
web.xml:<br />
<div class="separator" style="clear: both; text-align: left;"><br />
</div><div style="text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQlB21Eb9em4-oqOuOge8R94B6A_B8wEiIfpYfphkjodsSVTxlmoV2d5wTDelj7xumIZHs5HYp9kHx-aM2qO8Bir3BK5uCQnzWmzpklAxf8Wkb7_7yqXXqb-rWYnq4wdQHEJza3osUICs/s1600-h/11.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQlB21Eb9em4-oqOuOge8R94B6A_B8wEiIfpYfphkjodsSVTxlmoV2d5wTDelj7xumIZHs5HYp9kHx-aM2qO8Bir3BK5uCQnzWmzpklAxf8Wkb7_7yqXXqb-rWYnq4wdQHEJza3osUICs/s400/11.gif" /></a><br />
</div><div style="text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">And if we press “Run” button, and choose a server on which it is supposed to run<br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div style="text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNfMJt-XxjIOeit-eLegkOdqOI9OCmRlm_d2vBBgWzrnocn1MgiypMKJq5mjsbP3CxwBdlPxTa_amY3XlUp8H0GIIKLyDglR2aupaYP1wmVAbz1QVfRl72lkwB07p4MUhLV-hrvN_uVEI/s1600-h/server.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNfMJt-XxjIOeit-eLegkOdqOI9OCmRlm_d2vBBgWzrnocn1MgiypMKJq5mjsbP3CxwBdlPxTa_amY3XlUp8H0GIIKLyDglR2aupaYP1wmVAbz1QVfRl72lkwB07p4MUhLV-hrvN_uVEI/s400/server.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">we’ll get something looking like this:<br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCeIgmyBmXH7sCVQbWYwyh6AMesmc2CQsHCWTs3cWYlwxV4QamGBi9Z_eNNKLvdR3M_NNZiv03uOS3PU0xPFtEMmZsem3ve3Me0UZrUvCuFDLihUotBsb9lq1uVOMFk5HTGiNbeofJcxI/s1600-h/greska.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCeIgmyBmXH7sCVQbWYwyh6AMesmc2CQsHCWTs3cWYlwxV4QamGBi9Z_eNNKLvdR3M_NNZiv03uOS3PU0xPFtEMmZsem3ve3Me0UZrUvCuFDLihUotBsb9lq1uVOMFk5HTGiNbeofJcxI/s400/greska.gif" /></a><br />
</div><div style="text-align: left;"></div><div style="text-align: left;">But don't worry. Everything is OK, we just didin't handle default page...<br />
If we append <b>entername.action </b>on the URL , our new application will open:<br />
</div><div style="text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRFw7SfeiEuBn8kn4JQwQ_AImT6dniDwM0qaTrvjOAYi8YpXAoCfMUObDq0bhwIlV0dwerjv0uffYm37RcLZBryukB2o-LnH_Q6JrKlDOzjT1OuBmIt36z6iX0Y46UD-OltkV_fKuCnOE/s1600-h/12.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRFw7SfeiEuBn8kn4JQwQ_AImT6dniDwM0qaTrvjOAYi8YpXAoCfMUObDq0bhwIlV0dwerjv0uffYm37RcLZBryukB2o-LnH_Q6JrKlDOzjT1OuBmIt36z6iX0Y46UD-OltkV_fKuCnOE/s400/12.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: left;">If we do not enter name and press “submit”:<br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqTJ9jBq3OnJe91SM2gx6KwUngIBl9OK_t1RKFZ3Lr0IdRlNJB9CtYbpqB1dbqltzRlEypU36TiSc8hyA0WJvwL44FL1LuSqYFKb0GD_F5NAygjaLx4Z3KWcePh-76oXawwCZI5QsE45w/s1600-h/13.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqTJ9jBq3OnJe91SM2gx6KwUngIBl9OK_t1RKFZ3Lr0IdRlNJB9CtYbpqB1dbqltzRlEypU36TiSc8hyA0WJvwL44FL1LuSqYFKb0GD_F5NAygjaLx4Z3KWcePh-76oXawwCZI5QsE45w/s400/13.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">but if we do enter name and press “Submit”:<br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPHK_l7DIoisLU75sjFWoRiSXv71CvKDSTokLPPLjf8T83Bg5g7L3gKHAOvm5bNjHt-hzcCJUG0D8tNl117luGU9zUucZgAo_dDh_Gx9F2OG7v1lqrkOBw369FYnVrAPDm5pFGz4i01pc/s1600-h/14.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPHK_l7DIoisLU75sjFWoRiSXv71CvKDSTokLPPLjf8T83Bg5g7L3gKHAOvm5bNjHt-hzcCJUG0D8tNl117luGU9zUucZgAo_dDh_Gx9F2OG7v1lqrkOBw369FYnVrAPDm5pFGz4i01pc/s400/14.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">So, I hope I helped you to understand how to create an empty struts2 project in Eclipse Galileo.<br />
</div><br />
At the end, our project looked like this:<br />
<div class="separator" style="clear: both; text-align: left;"><br />
</div><div style="text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjY3zSAyc4Zs2iUwTA1uDA22WtNxIo3m4sVxBRZNrutWK-WvtLS-sIjRaSS6AUeuze8GEv0LdUXigD1qeMCnPlkDnprTnYCk8d74BVNTuvBMCLKwcOPaphnPs1qqPJDFFJ_lzynDwsdaY0/s1600-h/15.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjY3zSAyc4Zs2iUwTA1uDA22WtNxIo3m4sVxBRZNrutWK-WvtLS-sIjRaSS6AUeuze8GEv0LdUXigD1qeMCnPlkDnprTnYCk8d74BVNTuvBMCLKwcOPaphnPs1qqPJDFFJ_lzynDwsdaY0/s400/15.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div>A small conclusion of mine: great thing about Eclipse is that you can do just about everything with it , with just a little few extra settings and installations...<br />
Unfortunately, for me - many things and options remained a little bit more complicated and unintuitive regarding to some other IDEs. That is such a shame!<br />
Nevertheless , for me , Eclipse continues to be one of the best choices!.<br />
<br />
Enjoy Struts2 and Galileo! <br />
<div style="text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div></div></div>Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com75tag:blogger.com,1999:blog-2760857886315929363.post-92055314130345205422009-07-09T06:04:00.000-07:002010-01-21T06:18:24.581-08:00How to create Struts2 project in NetBeansIf you decide to start learning and using struts2, probably one of the first things you think about is which IDE to use, and what you need in order to create and run a Struts2 project...<br />
<br />
If you search the web , you'll find many tutorials on how to create a struts2 project, and start developing.<br />
This is what I did when I was starting, and soon find out that nothing I found on the web worked for me in proper manner...<br />
<br />
So, I decided to create a small tutorial on how to create an empty struts2 project , in order to help others, and save their time.<br />
Not to teach you Struts2, but to help you create a working Struts2 project!<br />
<br />
Ok, I will use NetBeans 6.5, and a Tomcat 6 that comes with it...<br />
<br />
First of all, go to <span style="font-weight: bold;">http://struts.apache.org/2.x/index.html</span> and download the latest version of Struts2.<br />
I downloaded struts-2.1.6-all.zip<br />
You won't be needing all the libraries in it. Just 6 of them. Because of this, you can download essential dependencies only.<br />
<br />
When you download one of these files, extract it to some location, for example: c:\Struts2<br />
It is now time to start a new project. Start NetBeans.<br />
<br />
Click <b>File -> New project -> Java web -> Web application</b><br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhtt42qdY1r6YP6Tw54LF98l0H9PYHqJ4IssEHXstaORUB0z8XVZ4PR2jDIGfD-80UaMj1Z0PJvkjUFDetRWEWexbwDAgBDnNVXUexJuG7b3XDx_JPqvhdnjSyHIiA5RkH0xa6G5DaufM/s1600-h/1.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhtt42qdY1r6YP6Tw54LF98l0H9PYHqJ4IssEHXstaORUB0z8XVZ4PR2jDIGfD-80UaMj1Z0PJvkjUFDetRWEWexbwDAgBDnNVXUexJuG7b3XDx_JPqvhdnjSyHIiA5RkH0xa6G5DaufM/s400/1.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">Let's name our project "<b>Struts2Example</b>". Click "next".<br />
</div>Choose which server you wish to use ( I selected Tomcat 6 ), set JavaEE to version 5, and leave ContextPath to be /Struts2Example<br />
<br />
You can click "finish" now.<br />
If you click "next" DO NOT, I repeat <b>DO NOT </b>choose available ( older version ) of struts under "frameworks".<br />
<br />
Your project tree will look this:<br />
<div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJU7B_dH58VlkXoc4d-CQNk85GfSdVg-JuBiJorpz6qQz8UUTXxf7nISXP_LnUYxom4CHCOopX6-d_ZqrB66CmGQKLSqoITVcsLVDJDEOTxhLqv77HFg6gQDEezJMAN7y7HgFNSjkGvMw/s1600-h/2.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJU7B_dH58VlkXoc4d-CQNk85GfSdVg-JuBiJorpz6qQz8UUTXxf7nISXP_LnUYxom4CHCOopX6-d_ZqrB66CmGQKLSqoITVcsLVDJDEOTxhLqv77HFg6gQDEezJMAN7y7HgFNSjkGvMw/s400/2.gif" /></a><br />
</div><br />
Now, in order to use Struts2 libraries, let's add those essential dependencies to project:<br />
<br />
Right click on "Libraries" folder and then click "Add JAR/folder". A dialog will open.<br />
Go to folder where you extracted Struts2 libraries and select ( add to project ) following files:<br />
<br />
<b>- struts2-core-2.1.6.jar<br />
- freemarker-2.3.13.jar<br />
- ognl-2.6.11.jar<br />
- commons-fileupload-1.2.1.jar<br />
- commons-logging-1.0.4.jar<br />
- xwork-2.1.2.jar</b><br />
<br />
Most of the tutorials on the web are written for older version of struts2, at the time when <b>commons-fileupload-1.2.1.jar </b>was not mandatory, so even when following all the steps in tutorial , you just couldn't get your project to work ( with newer version of Struts2 ) !<br />
<br />
Now, your project will loke like this:<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaa1pr4WyjtZbQ9I3vMgKcWaYC85HC-escmjjO-XH44ujA-3yrVIdkDb84xYBGOsyop6sA_loUMwrmmdXFYKhWzAq1bgZC99rOVnLauxPQjl9maQIXYuUbaH3CNpBJrfwDUr6XWUNPSSA/s1600-h/3.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaa1pr4WyjtZbQ9I3vMgKcWaYC85HC-escmjjO-XH44ujA-3yrVIdkDb84xYBGOsyop6sA_loUMwrmmdXFYKhWzAq1bgZC99rOVnLauxPQjl9maQIXYuUbaH3CNpBJrfwDUr6XWUNPSSA/s400/3.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">Now, in the root of WEB-INF folder create a new folder , and name it "lib".<br />
</div>Copy these six JARs into this new folder.<br />
<div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyE5pIH4x2_sJ3Zi7jjJ_FTeqnoOEAQ6J9KubV7Z516c_7bSAodJfvXuFUcZmln3r28HTfYGZ4hhpn-GQu5Kn5LC9-VXDKgtn3mNmtLfYx8fldqN3ZV0JJVNCz6MFY7VDg0JNJaETHvjk/s1600-h/4.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyE5pIH4x2_sJ3Zi7jjJ_FTeqnoOEAQ6J9KubV7Z516c_7bSAodJfvXuFUcZmln3r28HTfYGZ4hhpn-GQu5Kn5LC9-VXDKgtn3mNmtLfYx8fldqN3ZV0JJVNCz6MFY7VDg0JNJaETHvjk/s400/4.gif" /></a><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">These files will be uploaded to App Server , and a deployed application will use it.<br />
</div>We could put this files into main lib folder of application server, but it is most probably better this way...<br />
<br />
We need to create one more folder in the root of the WEB-INF , and name it "classes".<br />
This is where you will create <b>struts.xml</b>, and if needed - a <b>struts.properties</b> file.<br />
<div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdQfjT65yKwm5Vjgvx0HBt8-ohN2rTMXd_q156MrJAKO64MkfX1RnAGj2gS-9yn_lxXI0gMHvaPr5lmU7xV49LkdWXMqjP2gFwoSlDx48_11I2WfwzxudeIVro_wNHsqBrsOTNok5s6uw/s1600-h/5.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdQfjT65yKwm5Vjgvx0HBt8-ohN2rTMXd_q156MrJAKO64MkfX1RnAGj2gS-9yn_lxXI0gMHvaPr5lmU7xV49LkdWXMqjP2gFwoSlDx48_11I2WfwzxudeIVro_wNHsqBrsOTNok5s6uw/s400/5.gif" /></a><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">I'll put all my JSP's into new folder, "jsp" , which I will create in the root of "Web Pages" folder.<br />
</div><br />
All Java code that we write, we will place into some package in the "Source Packages" folder.<br />
I'll create one now, called "Struts2Example" and a "Hello" Class in it.<br />
If you use validaton, put all Validation XMLs inside class's package too...<br />
<div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj51jkfgeY_qWyLTg-zrEq34kDmURABbrucSZgN2R1_nrdnMr9-c9aQh8P4X78_anEQcyCsNv7nzCs0nrRImVytAWP6_WfDw7P_S7vplVFOuDC_1Xoj0dL_4BosiNF-O_3PnkPMGYaXz4w/s1600-h/6.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj51jkfgeY_qWyLTg-zrEq34kDmURABbrucSZgN2R1_nrdnMr9-c9aQh8P4X78_anEQcyCsNv7nzCs0nrRImVytAWP6_WfDw7P_S7vplVFOuDC_1Xoj0dL_4BosiNF-O_3PnkPMGYaXz4w/s400/6.gif" /></a><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">This is how, at minimum, your Struts2 project structure should look like.<br />
</div><br />
<br />
I'll create one small Struts2 application now. Nothing complicated.<br />
User will enter his name, and press "submit" and other page will open , saying Hello to this user.<br />
<br />
So, let's first create a Java class extending ActionSupport class , named hello, inside Struts2Example package.<br />
Let's make it to look something like this:<br />
<div class="separator" style="clear: both; text-align: left;"><br />
</div><blockquote><div class="separator" style="clear: both; text-align: left;">package Struts2Example;<br />
</div><br />
import com.opensymphony.xwork2.ActionSupport;<br />
<br />
/**<br />
*<br />
* @author Darko<br />
*/<br />
public class Hello extends ActionSupport<br />
{<br />
private String name, message;<br />
<br />
public String getName() {<br />
return name;<br />
}<br />
<br />
public void setName(String name) {<br />
this.name = name;<br />
}<br />
<br />
public String getMessage() {<br />
return "Hello " + getName();<br />
}<br />
<br />
public void setMessage(String message) {<br />
this.message = message;<br />
}<br />
<br />
}<br />
</blockquote><br />
We now need two JSPs, for example "nameinput.jsp" and a "response.jsp"<br />
Each JSP needs to contain this line, in order to use struts2 custom tags in it:<br />
<br />
<b> <%@ taglib prefix="s" uri="/struts-tags" %></b><br />
<br />
nameinput.jsp:<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7NhveH6ATrNj2aUreXI36zsIMkdfalCNNnvtgMyQRvFreRRJZrBtIY2REl-JCV4DYRZU9noFqzcFceNg3Hn24CxaznOclT5j_Ju9SfSxtSqxQ2nAn5BsH7sitvvtYiLGaxOqxIb8WD3A/s1600-h/nameinput.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7NhveH6ATrNj2aUreXI36zsIMkdfalCNNnvtgMyQRvFreRRJZrBtIY2REl-JCV4DYRZU9noFqzcFceNg3Hn24CxaznOclT5j_Ju9SfSxtSqxQ2nAn5BsH7sitvvtYiLGaxOqxIb8WD3A/s400/nameinput.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">response.jsp:<br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-trtHNIszEmugJU1fhGx7We3SXHwaOmHH1jSXyiGBWmlwwO0FPGrluCfvrykvgFHjA-NYPXFcDfHEqi7sVpT1q1Okm8RtE7_vgt44DjR3xpEWoVL7V_nZckDn4hwr77XkTWXW73AkE4k/s1600-h/response.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-trtHNIszEmugJU1fhGx7We3SXHwaOmHH1jSXyiGBWmlwwO0FPGrluCfvrykvgFHjA-NYPXFcDfHEqi7sVpT1q1Okm8RtE7_vgt44DjR3xpEWoVL7V_nZckDn4hwr77XkTWXW73AkE4k/s400/response.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">Let's create an XML validation file for Hello class, and make a <b>name</b> property mandatory. <br />
</div><div class="separator" style="clear: both; text-align: left;">Hello-validation.xml:<br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><blockquote><div class="separator" style="clear: both; text-align: left;"><!DOCTYPE validators PUBLIC<br />
</div>"-//OpenSymphony Group//XWork Validator 1.0.2//EN"<br />
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"><br />
<br />
<validators><br />
<field name="name"><br />
<field-validator type="requiredstring"><br />
<param name="trim">true</param><br />
<message>Please enter name</message><br />
</field-validator><br />
</field><br />
</validators><br />
</blockquote><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;">There's only 2 things left for us to do:<br />
</div><br />
Edit struts.xml, and web.xml:<br />
<div class="separator" style="clear: both; text-align: left;"><br />
</div><div style="text-align: left;"><br />
struts.xml:<br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQBtQV-XYk0nYjsJXrnQxhdhh4cMDcAyfL2zG6860YlUoOa2vSD-OaNDqhJ5crV1drt2pZTvo5mGtpGbTjKZYKrEutHU9zzNrxM7QOKFpBQLPEeJ8ZbyH9RbhH1nUH7YwGaQgEITk0lMA/s1600-h/7.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQBtQV-XYk0nYjsJXrnQxhdhh4cMDcAyfL2zG6860YlUoOa2vSD-OaNDqhJ5crV1drt2pZTvo5mGtpGbTjKZYKrEutHU9zzNrxM7QOKFpBQLPEeJ8ZbyH9RbhH1nUH7YwGaQgEITk0lMA/s400/7.gif" /></a><br />
</div><br />
web.xml:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrlxJM9s-D7SLI5N_mcnijhg1JaVzJiHhVoULKgdFl30IjOTO79I9nRK0KtnT-wvohQQ_bRFs_gXwOx3UGfXOtz2flhRVMxb257GUtOTtYXmrMupxm3WlpK9Zu245O93r8p1ISyrrbge8/s1600-h/8.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrlxJM9s-D7SLI5N_mcnijhg1JaVzJiHhVoULKgdFl30IjOTO79I9nRK0KtnT-wvohQQ_bRFs_gXwOx3UGfXOtz2flhRVMxb257GUtOTtYXmrMupxm3WlpK9Zu245O93r8p1ISyrrbge8/s400/8.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">and if you deploy this project to server, and open <br />
</div><div class="separator" style="clear: both; text-align: left;"><b>http://localhost:8084/Struts2Example/entername.action </b> , you'll get something like this: <br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYxVHiP75ssQxJ9rLSGh2cAyHjLK46PreESVeGvCwobhHEusjUHvTMcQKvHgUOO0QcyCHsJ4fuqlRqsJziee_z2R6PjExyOuWcze0MbyjSmTIyvIqwxoA_iziFqbTbrQts1JJgkMgtK3E/s1600-h/9.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYxVHiP75ssQxJ9rLSGh2cAyHjLK46PreESVeGvCwobhHEusjUHvTMcQKvHgUOO0QcyCHsJ4fuqlRqsJziee_z2R6PjExyOuWcze0MbyjSmTIyvIqwxoA_iziFqbTbrQts1JJgkMgtK3E/s400/9.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">If we do not enter name:<br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAegs5G07Brd_eI5hKOPS46egAttvGxBfKnpep_TW9KzQnjsmW69GaMF-B2ht7csucoxqONP5LC96Bd_XyhaWOH-RVV1CGQSZYXaAwccVOIez40R4cJumHdjt4E03-LiT0Gu_NJxP2-Xk/s1600-h/10.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAegs5G07Brd_eI5hKOPS46egAttvGxBfKnpep_TW9KzQnjsmW69GaMF-B2ht7csucoxqONP5LC96Bd_XyhaWOH-RVV1CGQSZYXaAwccVOIez40R4cJumHdjt4E03-LiT0Gu_NJxP2-Xk/s400/10.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">and if we do:<br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDwJx0vDduWBvvtfERNx6MRfN3Dlr0oQD5jQiWd_RZ2-oLrw_sMg5Rlmw9PFTKR7cdR86Vwtz6o_pWsK13f_N8ike_E8UfJWoxHwVR6evP2gYp407-su4PzfH0KizTLSv2MQ7CTiAoP-o/s1600-h/11.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDwJx0vDduWBvvtfERNx6MRfN3Dlr0oQD5jQiWd_RZ2-oLrw_sMg5Rlmw9PFTKR7cdR86Vwtz6o_pWsK13f_N8ike_E8UfJWoxHwVR6evP2gYp407-su4PzfH0KizTLSv2MQ7CTiAoP-o/s400/11.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">So, I hope I helped you to understand how to create an empty struts2 project in NetBeans.<br />
</div><div class="separator" style="clear: both; text-align: left;">At the end, our project looked like this:<br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhooWE2o21wQ6hoPNHyQgDen1SyLulC3fKkikFiXDsd_Qm94gkqQnyz2vAmReXUDjbZ71iEgMxzhg-9TbP9Ke30OSR9H0nBQ6B0glL0ODWc9kcuYKeE8Y0Yi-AdDq2_zQyz6twBHGmd5ho/s1600-h/13.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhooWE2o21wQ6hoPNHyQgDen1SyLulC3fKkikFiXDsd_Qm94gkqQnyz2vAmReXUDjbZ71iEgMxzhg-9TbP9Ke30OSR9H0nBQ6B0glL0ODWc9kcuYKeE8Y0Yi-AdDq2_zQyz6twBHGmd5ho/s400/13.gif" /></a><br />
</div><div style="text-align: center;"></div><div class="separator" style="clear: both; text-align: left;"><br />
</div><br />
There's more to it. For example, if you wish to override some theme's behaviour ( for example "simple" ) you create folders<br />
template/theme_name ( for example template/simple ) and it you copy all the original files from this theme ( from struts2-core-X.X.X.jar ) and edit them in this folder...<br />
<div class="separator" style="clear: both; text-align: center;"><br />
</div><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUPiLCon3dyhHI-gpSNmdVCqxq-LX1ddiE2F5fCEy_GqXMFMVtNWu7DwZjeopBCwyMQP6jxOZX71Ye0CunB0Cm69k9tjwQrJp8tcMZ2oHeej20mdmHiEHJfR1096L7kxS70tAXiw9ubl8/s1600-h/12.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUPiLCon3dyhHI-gpSNmdVCqxq-LX1ddiE2F5fCEy_GqXMFMVtNWu7DwZjeopBCwyMQP6jxOZX71Ye0CunB0Cm69k9tjwQrJp8tcMZ2oHeej20mdmHiEHJfR1096L7kxS70tAXiw9ubl8/s400/12.gif" /></a><br />
<div class="separator" style="clear: both; text-align: left;"><br />
</div>But, some other time about that and some other usefull things...<br />
<br />
Enjoy Struts2!<br />
<div style="text-align: center;"></div>Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com37tag:blogger.com,1999:blog-2760857886315929363.post-63946149754519239232009-06-30T01:43:00.000-07:002010-01-21T06:22:17.726-08:00Od sada i na baze-podataka.netOd prije malo više od nedjelju dana, moje tekstove možete pratiti i na <b>www.baze-podataka.net</b><br />
<br />
Radi se o jednom od mojih omiljenih sajtova koji svakodnevno posjećujem gotovo još od njegovog osnivanja, i lično - smatram da se radi o najkvalitetnijem domaćem sajtu na temu baza podataka, zbog čega mi je bila velika čast prihvatiti poziv Dejana Topalovića da budem jedan od autora.<br />
<br />
Nažalost, sve se desilo u periodu kada sam jako opterećen obavezama na poslu, pa za sada novih postova od mene nema, već sam samo, na Dejanov predlog, prenio jedan od tekstova sa <b style="color: #666666;">devtalks.blogspot.com</b><br />
<br />
<br />
<b> </b><br />
<b style="color: #666666; font-style: italic;">O sajtu</b><br />
<br />
Ko nije upoznat, baze-podataka.net je blog posvećen temama o bazama podataka , kako sa administratorske tako i sa programerske strane.<br />
Smatram da bi svako ko se bavi pomenutim poslom trebao ovaj sajt sačuvati pod svoje bookmarks-e , jer će sigurno uživati u tekstovima i naučiti nešto novo.<br />
<br />
<br />
<br />
Radujem se našem budućem druženju (i) na baze-podataka.net !Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com0tag:blogger.com,1999:blog-2760857886315929363.post-75531425403844333532009-06-17T05:12:00.000-07:002010-01-21T06:18:50.994-08:00Struts 2 Design and Programming: A Tutorial ( Book recommendation )There's <a href="http://devtalks.blogspot.com/2008/09/c-in-plain-english-book-recommendation_20.html">one more</a> book that I would like to recommend to you.<br />
It is called, well I assume you've already guessed, <b>Struts 2 Design and Programming: A Tutorial</b>.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiv7vnyuH-QTIWwuhxSDODn64ikZRHKF5pd4ofF8n-gjg2QjAnZFW0N5MpyT6q9XVEDpJEke6HLOptw96Pxsv04g1VqBm27Xt4UmDytxmdRjJ7brN_ZlPmLHhQttRn0fq2EdiDDN06v1yI/s1600-h/Struts2Design.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiv7vnyuH-QTIWwuhxSDODn64ikZRHKF5pd4ofF8n-gjg2QjAnZFW0N5MpyT6q9XVEDpJEke6HLOptw96Pxsv04g1VqBm27Xt4UmDytxmdRjJ7brN_ZlPmLHhQttRn0fq2EdiDDN06v1yI/s400/Struts2Design.jpg" /></a><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">If you'd like to learn Struts2 framework, then I think this is a good place for you to start!<br />
</div><br />
It is written for beginners who'd like to learn Struts2, but pros could also use it to refresh their memory on how some things could and should be done.<br />
<br />
What thrilled me most when reading this book was the fact it was written exactly as I would like it to be...<br />
<br />
Everything is explained very well, and there are a lot of useful examples...<br />
<div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;">You'll learn about MVC design pattern, struts2 tags, interceptors, input validations , type conversions, ajax in struts2 , tiles , some Tomcat settings, DAO design patterns and alot more...<br />
</div><br />
I really enjoyed reading it. <br />
<div style="text-align: center;"></div>Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com2tag:blogger.com,1999:blog-2760857886315929363.post-61386311282366207502009-06-17T04:42:00.000-07:002009-06-17T04:47:56.628-07:00Blackboard designer :-)Ovaj tekst niti je interesantan, niti će iko išta naučiti iz njega ili mu biti koristan, već sam ga napisao da bih ispravio sam sebe.<br /><br />Neki dan sam počeo sa dizajnom novog modula koji bi koristio bazu podataka, te uzeh da nacrtam ER dijagram kako bi baza za njega izgledala...<br /><br />U sred crtanja dijagrama za novu bazu sam se sjetio teme koja je nedavno pokrenuta na <a href="http://www.baze-podataka.net/2009/05/28/er-uml-case-tool-koji-alat-koristite-za-modelovanje-baze-podataka/">www.baze-podataka.net</a> o tome u čemu crtamo ER dijagrame.<br /><br />Tada sam napisao da koristim Oracle designer.<br /><br />Ne bi ni meni bio ništa interesatno, da sebe nisam uhvatio kako sam za crtanje dijagrama ipak prvo koristio dobri stari Blackboard designer, kojeg sam zaboravio navesti :-)<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlumjbsBPxyMhxNwON-P1St71K779x0HhGYzgaZzde6GvAZjfQeG02aUqpn2YoahRkqZnE1A0KW3iU7VpMJs3zB5mwjaYztHb-WKYj8ae3FZlw156s9A9TTstDMDk-bhSIHhcUpihnuz4/s1600-h/1.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlumjbsBPxyMhxNwON-P1St71K779x0HhGYzgaZzde6GvAZjfQeG02aUqpn2YoahRkqZnE1A0KW3iU7VpMJs3zB5mwjaYztHb-WKYj8ae3FZlw156s9A9TTstDMDk-bhSIHhcUpihnuz4/s400/1.gif" border="0" /></a> </div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: left;">Dobro, kada završim dijagram ipak ću sve prenijeti u Oracle designer jer je malo teže iz Blackboard designer-a izgenerisati bazu, a nigdje nisam ni na internetu našao kako ovo uraditi automatizovano :-) </div><div style="text-align: center;"></div>Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com2tag:blogger.com,1999:blog-2760857886315929363.post-31518133098051584852009-05-25T05:11:00.000-07:002010-08-21T05:43:57.378-07:00SQL Developer , nebrušeni dijamantObožavam maj.<br />
To je mjesec kada se u Crnoj Gori najviše praznuje.<br />
Prvo dođe 1. maj pa onda i 21. maj , prije toga u aprilu i uskrs<br />
i ako se “poklopi” da ovi dani padaju u četvrtak – petak , tu ukupno bude fin broj dana za odmaranje.<br />
<br />
To je razlog što me dugo nije bilo sa novim tekstom. Praznovalo se, što ću :-)<br />
<br />
Ako se ovome doda da sam u maju bio još i na ( zasluženom ) odmoru od ogromnog i iscrpljujućeg projekta – mogu reći da mi je ovaj maj bio poseban... :-)<br />
<br />
Međutim, majski praznični dani su u Crnoj Gori, na žalost, završeni :-(<br />
Ali nije ni to loše. Ja sam jedan od onih koji obožavaju svoj posao.<br />
A tu su i novi tekstovi na devtalks-u …<br />
<br />
Prije neki dan mi pade na pamet jedan duži tekst koji sam posvetio recenziji IDE-ova za rad sa Oracle-om, pisanju koda u PL/SQL-u, upita u SQL-u i slično, a koji nikada nisam objavio.<br />
Dakle, o alatima koji su u ponudi na tržištu, i moje impresije o istima.<br />
Konkretno – radi se o “PLSQL Developer”-u , “Toad”-u , “SQL Developer”-u i “SQL Manager 2007 Lite for Oracle”.<br />
Ja u principu nisam baš totalno zadovoljan alatima ove vrste za rad sa Oracle-om i ovo je upravo jedna kategorija IDE-a koje sam vrlo često mjenjao tokom rada sa pomenutom bazom ne bih li našao nešto što mi u potpunosti odgovara.<br />
<br />
Ovdje ću prenijeti samo dio teksta, i to onaj koji je posvećen Oracle-ovom SQLDeveloper-u.<br />
<br />
Dakle, ovako sam tada opisao ovaj alat:<br />
<br />
<blockquote><br />
<div style="text-align: center;"><b>SQL Developer</b><br />
</div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4VDRCsriIRKzexIfAdr-XBT8Sd24Rzmc3qD1hqrMcf2k2G_XxISUDzKsT88jsYv3OB-vnykbrJeGJVS85DfKRvK8zAOef2vkvICX75hIQ9aYkRgTmr92WhcgeYPG5E2M-4FUbNKgfAtU/s1600-h/sqldeveloper.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4VDRCsriIRKzexIfAdr-XBT8Sd24Rzmc3qD1hqrMcf2k2G_XxISUDzKsT88jsYv3OB-vnykbrJeGJVS85DfKRvK8zAOef2vkvICX75hIQ9aYkRgTmr92WhcgeYPG5E2M-4FUbNKgfAtU/s320/sqldeveloper.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">Ako pričamo o konkurenciji Toad-u, onda moramo na prvo mjesto staviti program koji nam dolazi pravo iz Oracle-a a koji je ranije bio poznat pod nazivom <b>Raptor</b>: <b>SQL Developer</b>.<br />
</div>Zaista svjetlo na kraju tunela, i pravo osvježenje!<br />
<div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcymqACesRBUe0kAt1LXjKXuhiEo33t_CLPhPeHNcCRnQSxA7ykkpXeFIifHc-8iXeUelF-HePpEXUKxLPJqOd_EMNKNXpOowO4uBK31Ex-QdoWYrHvFvE3-MlI30OA4gyH7QDTnREzA8/s1600-h/sqldeveloper-izgled.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcymqACesRBUe0kAt1LXjKXuhiEo33t_CLPhPeHNcCRnQSxA7ykkpXeFIifHc-8iXeUelF-HePpEXUKxLPJqOd_EMNKNXpOowO4uBK31Ex-QdoWYrHvFvE3-MlI30OA4gyH7QDTnREzA8/s400/sqldeveloper-izgled.gif" /></a><br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div></blockquote><blockquote><b> </b>Ovo je nešto što, po meni, najviše liči na jedan pravi alat za rad sa bazom podataka i razvoj aplikacija, kada je u pitanju Oracle.<br />
To što je pisan u Javi je u jednoj mjeri dobra stvar, a u najvećoj mjeri jako loša.<br />
Upravo je moja najveća zamjerka kod ovog programa uperena ka njegovoj brzini. Ustvari ne ka brzini izvršavanja naredbi toliko - koliko na brzinu renderovanja njegovog izgleda i brzinu jave u domenu GUI-ja inače.<br />
Znamo da Java baš i nije svjetski prvak u brzini kreiranja GUI objekata. E , tu ova mana dolazi do izražaja.<br />
Mislim da su momci iz Oracle-a mogli ovaj aspekt malo bolje uraditi. Pravi primjer brzog IDE-a pisanog u Javi kod kojeg nikada nemamo ovaj problem je npr. NetBeans ili Eclipse.<br />
Često mi se desi da nakon dugog rada u nekom drugom programu, kliknem da se vratim na SQL Developer, a onda moram da sačekam ko zna koliko ( dragocjenog ) vremena da mi se prikaže program sa svim elementima i trenutnim stanjem.<br />
Inače, ovo je možda jedina ozbiljnija zamjerka na ovaj program.<br />
Program ima veoma dobar code completion , ima podršku za CVS i subversion, stablo je veoma lijepo urađeno, pregledno je i brzo.<br />
Ima skoro sve elemente koje editor jednog savremenog IDE-a treba da ima.<br />
<br />
Pristup tabelama je veoma jednostavan i brz:<br />
Jednim klikom na neku tabelu nam se odmah otvara novi prozor sa svim informacijama po tabovima za odabranu tabelu.<br />
<br />
Tabela za prikaz podataka bi mogla biti puno ljepša , a njene ćelije malo većih dimenzija.<br />
<br />
Još jedna dobra stvar kod ovog programa je ta da ne moramo imati instaliran nikakav Oracle client kod sebe, jer za konekciju ne koristi tnsnames.ora već JDBC drajvere.<br />
<br />
SQL Developer sada zaista zaslužuje da mu se da šansa.<br />
<br />
Savjet:<br />
Svim korisnicima savjetujem da prije početka obavezno urade sljedeće:<br />
<br />
Tools -> Preferences -> Database -> Object viewer Parameters i štrikirajte “Automatically freeze object viewer windows” jer će se u protivnom svaka tabela na koju kliknemo jednom otvarati uvijek u jednom istom prozoru. Sada će se svaka tabela otvarati u posebnom prozoru.<br />
</blockquote><br />
<br />
Da , to je nešto što bih ranije rekao za ovaj alat, nakon nekoliko nedjelja rada u njemu i to u NE kritičnim situacijama, kada se mogu tolerisati određene gluposti koje IDE može izazvati.<br />
Tada mi je ovaj program zaista bio pravo osvježenje jer je izgledao oprilike onako kako sam ja zamišljao da bi jedan IDE za rad sa Oracle-om ( za developere, naravno ) i trebao izgledati.<br />
Ono što bih sada rekao za ovaj IDE je da ga se bar još neko vrijeme zaobilazi u širokom luku!<br />
On je OK da se kući koristi i za učenje, ali ako se odlučite za njega na nekom ozbiljnijem projekrtu - uvijek treba imati pored sebe i jedan od dokazanih alata.<br />
<br />
Zašto sam promjenio mišljenje? Pa kao prvo zato što sa ovim alatom nikada ne znaš na čemu si. Recimo da smo prepravili neku funkciju, paket, proceduru...<br />
Nakon kompajliranja istih uopšte nećemo znati da li je kompajliranje uspješno obavljeno, da li je novi objekat validan , u čemu je problem ako problem postoji ( ne prikaže se lijepo poruka kao u npr. Toad-u )…<br />
<br />
Evo još jedan primjer: Dešavaće vam se nekada da će program sam od sebe početi prikazivati neki view sa uduplanim kolonama, dok je u drugim alatima taj pogled sasvim OK. A onda ti ako nemaš na produkcionoj lokaciji još neki alat nećeš moći ništa dalje raditi oko pomenutog pogleda...<br />
<br />
Ako program ( kojem inače ne treba instalacija ) iskopiramo na neki drugi računar i pokušamo ga pokrenuti – tu nastaju tek posebne situacije i blokiranja računara...<br />
O fantomskom brisanju ili dodavanju znaka tačka-zarez ( ; ) na kraju kodova koje želimo iskompajlirati – ni da ne pričam!<br />
<br />
Sve u svemu – SQL Developer je zaista alat kojeg jedna tanka linija dijeli od odličnog alata i vjerovatno će to uskoro i postati, kada se isprave određene nebuloze koje postoje u njemu. Zaista je sjajno zamišljen.<br />
Mislim da Oracle mora sebi priuštiti jedan ovakav, ali bug-free i price-free alat po svaku cijenu.<br />
<br />
E, da , za kraj: jedva čekam maj 2010-e. :-)Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com4tag:blogger.com,1999:blog-2760857886315929363.post-8696707152176229212009-03-27T15:40:00.000-07:002010-08-21T05:44:06.183-07:00Easy_Logger for Oracle - Log every insert, update or delete for a table , with detailsWhen it comes to client's demands when creating some IS or designing a DB, very often there's a need to have a complete log of all actions on some table containing important data.<br />
I received a few such demands myself...<br />
<br />
Something like this isn't so hard to make it yourself.<br />
<br />
We could easily write a<br />
before insert or update or delete trigger and iterate through all the columns saving all old and new values into some log table.<br />
But what if we have many tables that needs such log? Writing all of these triggers would take a quite time...<br />
And what happens when we alter some of these tables?<br />
<br />
That is why I created "<span style="font-weight: bold;">Easy_Logger</span>".<br />
Thanks to Easy_Logger we can easily create and maintain logging triggers.<br />
<br />
Easy_logger is a PL/SQL package , so it can be applied only to Oracle.<br />
It is written in Oracle 10g. I didn't test it on any other version...<br />
<br />
So, how do we use Easy_Logger?<br />
<br />
First of all, you should run this script:<br />
<br />
<a href="http://www.kdarko.users.t-com.me/download/instal_EL_prerequisites.sql"><b>instal_EL_prerequisites.sql</b></a><br />
<br />
It will create a table called "EL" ( as <span style="font-weight: bold;">E</span>asy <span style="font-weight: bold;">L</span>ogger ) which will contain all of our logs.<br />
It has 6 columns:<br />
<br />
<blockquote>EL_ID - autoincrementing ID , primary key<br />
EL_TABLE - Table name for which the log is created<br />
EL_ACTION - Which action was logged ( insert, update or delete )<br />
EL_LOG - The log itself containing all the old and/or new values in a record<br />
EL_USER - User name which commited action<br />
EL_DATE - When was log created</blockquote><br />
If this script ended without errors, you can now download Easy_Logger package itself and apply it into your database:<br />
<br />
<b><a href="http://www.kdarko.users.t-com.me/download/EASY_LOGGER.pks">Package declaration</a></b><br />
<b><a href="http://www.kdarko.users.t-com.me/download/EASY_LOGGER.pkb">Package body</a></b><br />
<br />
<br />
If everything went well, and without errors, you can now start creating a logging trigger for any table you wish.<br />
I will explain now how to do this:<br />
<br />
When creating an Easy_logging trigger for some table, you need to specify some parameters , that are part of a record EL_PREFERENCES:<br />
<br />
it looks like this:<br />
<br />
<blockquote>TYPE EL_PREFERENCES IS RECORD (<br />
table_name varchar2(64),<br />
create_AFTER_trigger BOOLEAN := true,<br />
on_insert BOOLEAN := true,<br />
on_update BOOLEAN := true,<br />
on_delete BOOLEAN := true<br />
);</blockquote><br />
so, if you want to create an AFTER [{INSERT},{UPDATE},{DELETE}] TRIGGER, you would set "create_AFTER_trigger" variable to TRUE ( else, if you would like to create a BEFORE [{INSERT},{UPDATE},{DELETE}] TRIGGER, you would set "create_AFTER_trigger" variable to FALSE) .<br />
"Table_name" variable holds information about table's name for which you want to create a trigger,<br />
and "on_insert" , "on_update" and "on_delete" simply tells Easy_logger on which action should a trigger fire.<br />
After you set all of this variables, you need to call a procedure called <b>EASY_LOGGER.CREATE_TRIGGER()</b> by sending this PL/SQL record to it...<br />
<br />
<br />
<br />
<span style="font-size: xx-small;"><b> </b></span><br />
<span style="font-size: xx-small;"><b>EXAMPLE:</b></span><br />
<br />
if we want to make a trigger that fires on after inserting or deleting a record in a table called <span style="font-style: italic; font-weight: bold;">MY_TABLE</span>, we would execute following code:<br />
<br />
<blockquote>declare<br />
preferences EASY_LOGGER.EL_PREFERENCES;<br />
begin<br />
preferences.table_name := 'MY_TABLE';<br />
preferences.create_AFTER_trigger := true;<br />
preferences.on_insert := true;<br />
preferences.on_update := false;<br />
preferences.on_delete := true;<br />
EASY_LOGGER.CREATE_TRIGGER(preferences); <-- this is the procedure for creating a trigger!<br />
end;</blockquote><br />
or just call<br />
<br />
<blockquote>exec EASY_LOGGER.CREATE_TRIGGER('MY_TABLE',true,true,false,true);</blockquote><br />
(notice that arguments for this procedure are exactly in the same order as variables in EL_PREFERENCES record)<br />
<br />
and a code for creating a logging trigger will generate in <b>dbms_output</b>, so don't forget to <i><b>set serveroutput on</b></i>!<br />
<br />
All that there is left for you to do is to execute generated code, and you'll have your logging trigger for <span style="font-style: italic; font-weight: bold;">MY_TABLE</span> table created.<br />
<br />
For those who need generated code as a returning value, and not as <i><b>dbms_output</b></i> output, there is a function called <b>get_trigger_ddl </b>which has no input parameters.<br />
It returns last generated trigger's DDL . <br />
<br />
You can call it like this:<br />
<br />
<blockquote>declare<br />
your_variable clob;<br />
begin<br />
EASY_LOGGER.CREATE_TRIGGER('MY_TABLE',true,true,true,true);<br />
your_variable := EASY_LOGGER.get_trigger_ddl();<br />
<b>... </b> <i style="color: #6aa84f;">-- do whatever you like with generated code...</i><br />
end;</blockquote><br />
That's it!<br />
Every action specified when creating logging trigger will be logged in EL table. <br />
I hope you'll like it...<br />
You are free to report any bug, or suggest any good idea for me to implement in order to make Easy_logger better...Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com4tag:blogger.com,1999:blog-2760857886315929363.post-85278259873725732792009-03-09T03:37:00.000-07:002010-03-03T02:42:05.994-08:00My N.A.N.Y. 2009 entry - generator for creating document containing info about all user tables and constrains in oracleFor this post, I decided to tell you a little bit more about my N.A.N.Y. 2009 entry.<br />
<br />
As I said on donationcoder.com , I started writing this application because I needed to create a document at work, just like the one that this application generates.<br />
For the past year, I was working on a large project , and at one point – I needed to provide a complet list of all tables and constraints for several users in DB that we created...<br />
I, maybe, could use some existing application to do this, but I wanted to make it myself<br />
;-) . Specially when half of work was already done, because I used queries provided by Olivera at <a href="http://www.insidedev.blogspot.com/">www.insidedev.blogspot.com</a><br />
<br />
<br />
<br />
So, how do we use it?<br />
First of all, download it from<br />
<a href="http://www.kdarko.users.t-com.me/downloads/MGTD.zip">http://www.kdarko.users.t-com.me/downloads/MGTD.zip</a><br />
and extract all files and folders to some installation dir.<br />
<br />
To start the application, run “RUN MGTD.bat” and a login window will appear.<br />
<br />
<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwkbCgu0UF5KyBjbZ1v_5UolYgWi9xXAGNhVGC53B6O9hcxkKdW30RX8Ad9Bv9MV-Yxrkzn8OYEfoaHsVgc9982Tt_izWxmNPpln2d57axxCRDqR86fvoFktpnchPt9_eAtiSDbqdO5A0/s1600-h/login.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwkbCgu0UF5KyBjbZ1v_5UolYgWi9xXAGNhVGC53B6O9hcxkKdW30RX8Ad9Bv9MV-Yxrkzn8OYEfoaHsVgc9982Tt_izWxmNPpln2d57axxCRDqR86fvoFktpnchPt9_eAtiSDbqdO5A0/s320/login.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="MsoNormal"></div><div class="MsoNormal">enter all parameters and click “connect”.<br />
</div><div class="MsoNormal"></div><div class="MsoNormal">New window, containing all user tables will appear.<br />
</div><div class="MsoNormal"></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjq_h73Ug673A2-_56OoOtUmc2LHZx7zALao9bfgrwLD48e5FWxvxwg2wFtIUDGgoOcJhTha7nEhGETIoar9pXT3z7QFnjX1vhPW-gd6CP7oNym7gcMgbhMKCgh_tJYHyHY2s4vswueJRY/s1600-h/mgtd.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjq_h73Ug673A2-_56OoOtUmc2LHZx7zALao9bfgrwLD48e5FWxvxwg2wFtIUDGgoOcJhTha7nEhGETIoar9pXT3z7QFnjX1vhPW-gd6CP7oNym7gcMgbhMKCgh_tJYHyHY2s4vswueJRY/s320/mgtd.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div style="text-align: left;">Here , we can decide which tables we want to process. We can do that by applying certain filter , or just by excluding some tables.<br />
<br />
Next thing we need to do is to set some things. We do this in “settings” tab.<br />
Here we can select what kind of constraints we want to generate information for.<br />
<br />
Also, we can select which colors to use when generating document.<br />
<br />
I’ll use default colors, except for table containing colums of current table.<br />
I’ll use yellow for it.<br />
<br />
And, before we start generating a document, we need to define a location for our document …<br />
I’ll use <b>c:\MGTD</b><br />
</div><div style="text-align: left;"><b> </b><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbeSIjcPb9iBkgokmlAKAerB0DQZm6jWo2xSR3D7DoGNH9nPfCY3ceIz3DJEQeZyKc5BP8WJvpBhhcFNJhg_M7teSaZHxXSDsMlD58i8lww-2jW2RiAFtWgUVzaFuUNq2_pUvQ3M1it_Y/s1600-h/settings1.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbeSIjcPb9iBkgokmlAKAerB0DQZm6jWo2xSR3D7DoGNH9nPfCY3ceIz3DJEQeZyKc5BP8WJvpBhhcFNJhg_M7teSaZHxXSDsMlD58i8lww-2jW2RiAFtWgUVzaFuUNq2_pUvQ3M1it_Y/s320/settings1.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">When you’re ready – press Execute.<br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVtsetx1abHU7TNiCg2H_y5DFOFh9zK7lJuwQhZ8u0WGiFx5-PW5X7SDSt_b6D3WCsYh78zReYcdd405mVaHKB9Jo8S8XpEPgiFm88bA2xSVaLqaov8HppNmkL0HCFMFhTTnEXBGYL0A0/s1600-h/gen.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVtsetx1abHU7TNiCg2H_y5DFOFh9zK7lJuwQhZ8u0WGiFx5-PW5X7SDSt_b6D3WCsYh78zReYcdd405mVaHKB9Jo8S8XpEPgiFm88bA2xSVaLqaov8HppNmkL0HCFMFhTTnEXBGYL0A0/s320/gen.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">And when progress bar reaches 100%, you will have your document created…<br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5shJ7qarJ4gDjRD67J7jRaEGR2TfCSu2CmHcIpjviuZTrKqT2s1n9ZJw87lW2n-Bw1JOw-GE0Gd84RkUclEgOkOP1EJi8OKF4ixmCeWKj2sN5x8ysI_kHrD9N9ZLXLLE-p2UgKJRsG74/s1600-h/doc.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5shJ7qarJ4gDjRD67J7jRaEGR2TfCSu2CmHcIpjviuZTrKqT2s1n9ZJw87lW2n-Bw1JOw-GE0Gd84RkUclEgOkOP1EJi8OKF4ixmCeWKj2sN5x8ysI_kHrD9N9ZLXLLE-p2UgKJRsG74/s320/doc.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="MsoNormal">Every table is described ( what columns it contains , what data type ( ans size of it) , nullable? information and a comment ) and there is also a list of all constraints for that table ( Primary keys, Checks, Foreign keys and Unique keys ).<br />
</div><div class="MsoNormal">As you can see, table containing info about columns names and type are in yellow, like we wanted it to be…<br />
</div><div class="MsoNormal"></div><div class="MsoNormal">Now when we have html document, we can easily create a .doc or .pdf …<br />
</div><div class="MsoNormal"><o:p> </o:p><br />
</div><div class="MsoNormal">Not many people will find it usefull, but for those who need something like it, it's more than helpfull, and I hope they'll like it...<br />
</div><div class="MsoNormal"></div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div style="text-align: center;"><b> </b><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="MsoNormal"></div><div class="separator" style="clear: both; text-align: center;"><br />
</div>Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com0tag:blogger.com,1999:blog-2760857886315929363.post-12951123410998996802009-01-06T01:06:00.000-08:002010-01-21T06:21:17.451-08:00Završen je N.A.N.Y. 2009Kao i prethodne dvije, tako je i ove ( ustvari, trebalo bi reći prošle ) godine uspješno organizovan , a još uspješnije završen <b>N</b>ew <b>A</b>pplication for the <b>N</b>ew <b>Y</b>ear challenge, iliti: <b>N.A.N.Y. 2009</b><br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8eyDN8yqoOUyK5WMmNtV1osewTAbAnsX9amzYJe5TT10hqIA_4Yxhyphenhyphenrf0PZbubmW4n7jhvGkgyBgOsgn7n-apbviVL6nvnILHEUeSFKtiuNBx_Qagz7rs6Sn9HF3nyXimXlpiw23jnuA/s1600-h/nanymug2009A1small.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8eyDN8yqoOUyK5WMmNtV1osewTAbAnsX9amzYJe5TT10hqIA_4Yxhyphenhyphenrf0PZbubmW4n7jhvGkgyBgOsgn7n-apbviVL6nvnILHEUeSFKtiuNBx_Qagz7rs6Sn9HF3nyXimXlpiw23jnuA/s400/nanymug2009A1small.png" /></a><br />
</div><br />
<br />
<br />
O čemu se radi?<br />
Pa, ukratko, momci sa DonationCoder-a su došli na ideju da se developeri , koji su u stanju da u mjesecu decembru odvoje koji trenutak svog slobodnog vremena, zajedno okupe i svijetu za novu godinu poklone ( najmanje ) jednu totalno novu aplikaciju, nikada prije objavljenu.<br />
<br />
Challenge počinje negdje početkom decembra i traje do 31 decembra, do 23:59.<br />
<br />
Svi koji do tada, na pomenutom sajtu, objave novu aplikaciju su učesnici ovog challege-a ( Oprostite što ne prevodim riječ challenge, jer mi “izazov” ili slično ne zvuči baš kao najsrećniji prevod... ) .<br />
<br />
Ove godine su učestvovala 44 programera, a svjetlo dana je ugledalo 35 novih aplikacija.<br />
<br />
Čitava “manifestacija” je pokrenuta prije godine, od stane Jesse Reichler-a, osnivača sajta i koordinatora ogromnog comunity-ja koji stoji iza samog sajta, inače sjajnog programera.<br />
<br />
Programski jezik i priroda aplikacije su totalno nevažni ( dok se, naravno, ne radi o malicioznim programima ) .<br />
<br />
Kao i 2006-e , i ove godine je učestvovala moja malenkost.<br />
Hmmm… ne bih se baš mogao svrstati u onu grupu developer-a koji su imali slobodnog vremena u decembru , zbog svih obaveza oko projekata na poslu, ali sam ipak odlučio učestvovati ove godine.<br />
Upravo zbog nedostatka slobodnog vremena sam se odlučio predstaviti malom aplikacijom nazvanom MGTD ( ne pitajte me šta znači :-) ).<br />
<br />
Nagrade su simbolične, ali veoma simpatične. Ljudi ovdje ne učestvuju zbog para. Uglavnom su to šolje ( one velike, za bijelu kafu ) sa logom takmičenja za tu godinu, a ako se takav poklon učesniku ne sviđa , onda može odabrati i neku drugu stvarčicu sa DonationCoder-ove sekcije caffepress-a.<br />
<br />
<br />
Prošle godine nisam učestvovao, pa sam možda i zbog toga odlučio da se ove godine pojavim.<br />
<br />
Uglavnom, za ovu priliku sam kreirao malu i ( meni, a i možda određenom , manjem, broju ljudi ) korisnu aplikaciju.<br />
Riječ je o aplikaciji koja za definisanog korisnika unutar baze podataka (Oracle-a) generiše HTML fajl sa pregledom svih njegovih tabela, kao i svih constraint-a unutar tih tabela.<br />
Moguće je i zadati filter za koje tabele želimo generisati fajl, i još neke sitne zafrkancije.<br />
<br />
Ništa posebno, ali opet kažem, meni je korisno. A i ne samo meni. Svi koji rade sa Oracle RDBMS-om na ovaj način mogu svom klijentu dopremiti opis tabela korisnika koji postoje u sklopu IS-a koji ste kreirali...<br />
Da, znam da se ovakav document može dobiti i kroz Oracle Designer, ali šanse nema da se mogu sjetiti gdje se nalazi dugme koje ga kreira, a i ovako je interesantnije ? .<br />
<br />
<br />
Nadam se samo da sam dobro napisao upite za sve ? .<br />
<br />
Htio sam implementirati i čuvanje u PDF, RTF i DOC format, ali stvarno nisam imao kad, a i kada imamo html, sve ove fajlove možemo veoma lako kreirati ;-).<br />
<br />
Čitava aplikacija je rađena u JAVI , i potrebna je verzija 1.6 da bi sve radilo. Dobro, radiće vjerovatno is a verzijom 1.5, ali je nemam instaliranu pa ne garantujem ;-).<br />
<br />
<br />
<br />
N.A.N.Y. challenge nije jedino takmičenje/okupljanje ovog tipa na pomenutom sajtu. Veoma često se organizuju razna vrsta takmičenja u programiranju, kreiranju igrica i slično, na kojima su nagrade zaista impresivne.<br />
A opet ima i onih sa simboličnim nagradama ( slično ovom ) kao što je npr. <b>G</b>etting <b>O</b>rganised <b>E</b>xperiment, iliti <b>GOE</b>, koje se održava otprilike neposredno pred N.A.N.Y. challenge.<br />
<br />
Prošle godine sam učestvovao i na ovom takmičenju.<br />
<br />
Mislim da čovjek treba sebi s vremena na vrijeme sebi priuštiti nešto slično, gdje će za svoju dušu kreirati nešto…<br />
E sad, ovo i nije baš bilo za moju dušu jer mi je ovakva aplikacija trebala za kreiranje istog dokumenta na poslu, pa sam je iz tog razloga i počeo praviti ( s tim da je prava (moja) verzija na našem, a ne engleskom jeziku ).<br />
<br />
Ali, zato sljedeće godine… ;-)<br />
<br />
<br />
Nepisano je pravilo da se učesnici takmičenja na DC-u slikaju sa poklonom/nagradom koju su osvojili/dobili i tu sliku “okači” na forum. Kada mi stigne ovogodišnja nagrada, pohvaliću vam se, uz sliku iste.<br />
Evo , možda je lijepa prilika da podjelim sa vama par slika sa nagradama koje sam dobio na takmičenjima/okupljanjima na ovom sajtu proteklih godina.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLZfHGV4CxO7EvosRy5ZP_4rE5M-UfhDywJNFXSqe-jjjmmN1_SpAx5PJ4VwIk90sO0pldm6pGBZ7A2qMdEJGc1G-AAQvlkYmdGyb6jicZpBNIN82ZaijBicb49v-qPtJNCMj-O1mEoLg/s1600-h/bds2006.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLZfHGV4CxO7EvosRy5ZP_4rE5M-UfhDywJNFXSqe-jjjmmN1_SpAx5PJ4VwIk90sO0pldm6pGBZ7A2qMdEJGc1G-AAQvlkYmdGyb6jicZpBNIN82ZaijBicb49v-qPtJNCMj-O1mEoLg/s320/bds2006.gif" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqHgswXCkmg5V_8FSFvyu5VDG-y7SOhfmuTZVhLPaeQWvJGwpPEAqFN7IFPa_9UO9CAla0meEyV3LAOCc1EL4De6rQBeXKLAoUz94KDeHoOTLPUHLRMA588nw2FbwlooPcFZ_WOgo-hFQ/s1600-h/006.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqHgswXCkmg5V_8FSFvyu5VDG-y7SOhfmuTZVhLPaeQWvJGwpPEAqFN7IFPa_9UO9CAla0meEyV3LAOCc1EL4De6rQBeXKLAoUz94KDeHoOTLPUHLRMA588nw2FbwlooPcFZ_WOgo-hFQ/s320/006.jpg" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjo3ZppiDtKP0Ri6tdjGX15C9H95N9aW0D6_oTtrH7B-Zde5gVR5gqxDfmVgeIhI_Qz3MFIe8ibvkf78ml19Fs3xbUL0L9rc86E61nvTXrKe0fu4AsxO_Oo22Q-iDglNWDFAMzmhurRWGA/s1600-h/Image(198).jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjo3ZppiDtKP0Ri6tdjGX15C9H95N9aW0D6_oTtrH7B-Zde5gVR5gqxDfmVgeIhI_Qz3MFIe8ibvkf78ml19Fs3xbUL0L9rc86E61nvTXrKe0fu4AsxO_Oo22Q-iDglNWDFAMzmhurRWGA/s320/Image(198).jpg" /></a> <br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">Možda se vidimo na nekom sljedećem okupljanju? <br />
</div><div style="text-align: center;"></div>Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com0tag:blogger.com,1999:blog-2760857886315929363.post-19486747614802941432008-12-03T06:46:00.000-08:002010-01-21T06:22:43.775-08:00How to create and use web services in NetBeansI think web services are one of the coolest things in programming. I will now show you how to create and use a web service in NetBeans.<br />
<br />
Let’s create a new web application project.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMk44mq2fg09Mp4cuv5cSh2p05Rg9aBZjNANVsi5Jle38WJQmKYUw8i9mnL6rWiyI90Pa98cQLjHp0J9asTyHtYkgD5JMHxzB-KrEjUTTpiqV9b511sJLQDdLoIUvuUj3mkXVFIS2oa3Y/s1600-h/new-project.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMk44mq2fg09Mp4cuv5cSh2p05Rg9aBZjNANVsi5Jle38WJQmKYUw8i9mnL6rWiyI90Pa98cQLjHp0J9asTyHtYkgD5JMHxzB-KrEjUTTpiqV9b511sJLQDdLoIUvuUj3mkXVFIS2oa3Y/s400/new-project.gif" /></a><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">Call it “WebServices”. Press Finish.<br />
</div>After a new project is created and opened, right click on the project, and choose “New -> Web Service”<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwEuYgdLxYUR37w-MEh5lLQtb1wSRHmpwepyICbmeeNSQrlqmEFI6aiMNzBsFB0lTfMVQpc8lYsKhY2JEeLJoAlZ0MMGcs24CxVOfTchh7K0s372Ulc6zLMg9v7yBL4_jw3mKSsljVAnI/s1600-h/new-web-service.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwEuYgdLxYUR37w-MEh5lLQtb1wSRHmpwepyICbmeeNSQrlqmEFI6aiMNzBsFB0lTfMVQpc8lYsKhY2JEeLJoAlZ0MMGcs24CxVOfTchh7K0s372Ulc6zLMg9v7yBL4_jw3mKSsljVAnI/s400/new-web-service.gif" /></a><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">Let’s say we want to create a web service that provides us a full name of the country whose national domain we send to the web service.<br />
</div>For example, if we send “<b>it</b>”, the web service return us “<b>Italy, Europe</b>”.<br />
So, let’s give this web service a “<i><b>CountryDomain</b></i>” name, inside “countries.tools” package.<br />
<div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6RB9JMymcygYl3S2706oViGU7jliQ21Kv3nVHiLKCTZfdMu6fCmuBRwjADtzMkssSkDi94Pwn6eE3qrE7GJTLk3r8_xBDp07P76MXbEMPz2eYeSstQXy4AyLi_EqyT-cI5YSFCvWbhcc/s1600-h/CountryDomain.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6RB9JMymcygYl3S2706oViGU7jliQ21Kv3nVHiLKCTZfdMu6fCmuBRwjADtzMkssSkDi94Pwn6eE3qrE7GJTLk3r8_xBDp07P76MXbEMPz2eYeSstQXy4AyLi_EqyT-cI5YSFCvWbhcc/s400/CountryDomain.gif" /></a><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">When we press “finish”, a new Tab will open offering us to create a web service by typing a code , or to create it with a provided visual designer.<br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzadV1aFvBo3ZUNGii7dNirrD6_JE1XLUZkiYa1G4x62kIcGfKrniVuYZsKCHXWN5woZNju8ISsxGnZZZnrE_znxMDbMxaUzfbktrQvAfxQ5wSeOQ5PTqeKYRUP0sxX0d1wlKdLkFvaDk/s1600-h/VB.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzadV1aFvBo3ZUNGii7dNirrD6_JE1XLUZkiYa1G4x62kIcGfKrniVuYZsKCHXWN5woZNju8ISsxGnZZZnrE_znxMDbMxaUzfbktrQvAfxQ5wSeOQ5PTqeKYRUP0sxX0d1wlKdLkFvaDk/s400/VB.gif" /></a><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">We will use a designer.<br />
</div><br />
Click on the “Add operation” button.<br />
A new window will open, asking us how we want to call this new operation, and to define a return type and parameters.<br />
In our example, the return type is <b>java.lang.String</b><br />
and the parameter is a String: <b>domain</b><br />
<div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgj76mAgwgwMipq-zw6SkiTv2XOm4vRETi8IYieu-PdVwIPkQA0Gc8ADbAeI0EvkLy-yjtwhYbfgGPyxamgosIn7vfLB8jpUW1rJNPgIOW5k_mzpaWgg_vHp9e6iOXliejYH4P7woQvwqE/s1600-h/new_operation.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgj76mAgwgwMipq-zw6SkiTv2XOm4vRETi8IYieu-PdVwIPkQA0Gc8ADbAeI0EvkLy-yjtwhYbfgGPyxamgosIn7vfLB8jpUW1rJNPgIOW5k_mzpaWgg_vHp9e6iOXliejYH4P7woQvwqE/s400/new_operation.gif" /></a><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">Press ok.<br />
</div>Now if we look at the visual designer, we will se that there is an operation that we created, and if we look at the code, we’ll see that the NetBeans generated a definition of our new operation.<br />
Now, we have to write it’s implementation.<br />
<br />
I won’t complicate things up now and use some database, from which I would collect information about country whose domain I receive, so I’ll just use some HashMap with some countries listed in it …<br />
<br />
So, let’s write some code in our web service. In the constructor I will initialize our HashMap with some countries, and in our getCountry operation, I will provide a code that will return a country name.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEje3_YQv3LyatiLgEyU3kbPfgH_djQDJvzacvKSyEhRqU_9R62Gwd33b7m92oc5ebSYuO3FViJ-QiHk6ufBVr3vOUQ8M_ulynAJDZIQaBSZzvfc4PyVzflHCODRdtlkntBwN-b2x4uxjMU/s1600-h/code.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEje3_YQv3LyatiLgEyU3kbPfgH_djQDJvzacvKSyEhRqU_9R62Gwd33b7m92oc5ebSYuO3FViJ-QiHk6ufBVr3vOUQ8M_ulynAJDZIQaBSZzvfc4PyVzflHCODRdtlkntBwN-b2x4uxjMU/s400/code.gif" /></a><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">And now, only thing left for us to do now, is to deploy this web service. I will deploy it on glassfish server that comes with netbeans.<br />
</div>To deploy it, right click on the project node, and select “<b>undeploy and deploy</b>”.<br />
<div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGiYli-4wIqNwYmO0HC8gqpEKaGLqOBc8swLrV-RaotqVn_zx2TCoJ3JND2xpt1boMuxGKmYwh3if2Qe05llQxFWU8zBhzEzEt5e1KsDytZldjgruCm2gMjf2NZjnTgm6tnrHFAb9WLZA/s1600-h/deploy.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGiYli-4wIqNwYmO0HC8gqpEKaGLqOBc8swLrV-RaotqVn_zx2TCoJ3JND2xpt1boMuxGKmYwh3if2Qe05llQxFWU8zBhzEzEt5e1KsDytZldjgruCm2gMjf2NZjnTgm6tnrHFAb9WLZA/s400/deploy.gif" /></a><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">After it’s deployed, it’s time to test it.<br />
</div>Right click on the web service that you made , and select “test web service”.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhp6KkV6wRHMy2LoAh_1zjK1JiD5TjktyhDPSCO9AzbWqWsZGOR8t8krAKji4DYIzjhHf1bfpVNSSBa7kzvxN8t7_XtCIQ4PNoHh0lIJDA0v3xI1ff6a72RIgQGfHhvDxc6j5ak7jXTGq8/s1600-h/test.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhp6KkV6wRHMy2LoAh_1zjK1JiD5TjktyhDPSCO9AzbWqWsZGOR8t8krAKji4DYIzjhHf1bfpVNSSBa7kzvxN8t7_XtCIQ4PNoHh0lIJDA0v3xI1ff6a72RIgQGfHhvDxc6j5ak7jXTGq8/s400/test.gif" /></a><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">A browser will open, and it will look something like this:<br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhikNuz9rBPcB7UhO5Hp1zkhyphenhyphen9VhN6JjauoMmEdMKWtWSuXoD4OMCsQC8TS_NnrJMPCtpE-qr43W36JcYVZa6cWckUo4aJmhLVvpoo7LJ1iyji9HTlviq4I6yZ069O_jskrgu364tuqmLk/s1600-h/browser.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhikNuz9rBPcB7UhO5Hp1zkhyphenhyphen9VhN6JjauoMmEdMKWtWSuXoD4OMCsQC8TS_NnrJMPCtpE-qr43W36JcYVZa6cWckUo4aJmhLVvpoo7LJ1iyji9HTlviq4I6yZ069O_jskrgu364tuqmLk/s400/browser.gif" /></a><br />
<div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">If we enter “it” ( as Italy ) , for example, and hit “getCountry” button, we’ll get a result “Italy, Europe”, or if we enter some not-existing domain ( not existing in our HashMap ) we’ll get a "Not a valid national domain" result.<br />
</div><br />
<br />
Nice, isn’t it? ?<br />
<br />
<br />
<br />
Now, how can someone use it in it’s code?<br />
<br />
The following example shows us how to do it.<br />
<br />
Let’s , once again, create a new Web Application project. let’s call it “CountryChecker”. Press Finish.<br />
<br />
A new project will open.<br />
Now, in order to use some web service, we need to know it’s URL. I’ll use CountryDomain ‘s URL <b>http://localhost:8080/WebServices/CountryDomainService?wsdl</b><br />
<br />
In order to use some web service in your code, we need to create a new web service client<br />
<div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgvWK_PAyyedVvV1zyQspF5qyK0OW9b7-LK3Vlfxth0nUxDmYUPTU-Zle_VtWaBpXVXUZqX8nqxz8BwZrwhtU0vvmxCWxS31tjBxuACzbni1m23cnd7ovGV4HT1huUWnQhItuYCctJFmo/s1600-h/web_service_client.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgvWK_PAyyedVvV1zyQspF5qyK0OW9b7-LK3Vlfxth0nUxDmYUPTU-Zle_VtWaBpXVXUZqX8nqxz8BwZrwhtU0vvmxCWxS31tjBxuACzbni1m23cnd7ovGV4HT1huUWnQhItuYCctJFmo/s400/web_service_client.gif" /></a><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">It will take some time for NetBeans to create it. When it does, you’ll get something like this:<br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWpNC1UNMGD7k44bIuN_AZ6KsdKqTBkZNjjHN5P_e97q57hKHRSZgfhxSPeTP7pyDQiiuTR_pQ5-RWPYgbkbFVzouTPXDB_YfUAqOQhOM99wBQQcxLeDmKsh4Huz6LnHdeJ1le5-gKUiU/s1600-h/web_reference.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWpNC1UNMGD7k44bIuN_AZ6KsdKqTBkZNjjHN5P_e97q57hKHRSZgfhxSPeTP7pyDQiiuTR_pQ5-RWPYgbkbFVzouTPXDB_YfUAqOQhOM99wBQQcxLeDmKsh4Huz6LnHdeJ1le5-gKUiU/s400/web_reference.gif" /></a><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">And now we come to the best part:<br />
</div><br />
If you want to use this web service in some of your web pages, just drag and drop it’s method onto your page, and NetBeans will generate the entire call.<br />
<br />
<div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXEG4PYgFEJF6LfqOmhrKfinWN_GUfEss10w8uE74CJpofI1o3tCJgEsbkBFOt0cMLg5CersEoVj_ruesFRy1w197eMlThxGKi5w93syYysDzC1pLTe7ehrb0b9VqwOeRs9cvk5Gfti8E/s1600-h/drag.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXEG4PYgFEJF6LfqOmhrKfinWN_GUfEss10w8uE74CJpofI1o3tCJgEsbkBFOt0cMLg5CersEoVj_ruesFRy1w197eMlThxGKi5w93syYysDzC1pLTe7ehrb0b9VqwOeRs9cvk5Gfti8E/s400/drag.gif" /></a><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">and when we open this web page, we will get:<br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFtJB1QLeOEx4_2LnwFc1drQX7JOKtfGZKRcV_8G2x1wTZxfzoFtOSTr_BGgKenrlJkS-eLntVzJtxPk3y57kjFXkS6XBr3dSD3WpjYnz5zLB1MqJDsWjWxgxmCpjT9heGkHBQvbDxAek/s1600-h/rezultat.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFtJB1QLeOEx4_2LnwFc1drQX7JOKtfGZKRcV_8G2x1wTZxfzoFtOSTr_BGgKenrlJkS-eLntVzJtxPk3y57kjFXkS6XBr3dSD3WpjYnz5zLB1MqJDsWjWxgxmCpjT9heGkHBQvbDxAek/s400/rezultat.gif" /></a><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div style="text-align: center;"></div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div style="text-align: center;"></div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div style="text-align: center;"></div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div style="text-align: center;"></div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div style="text-align: center;"></div><div style="text-align: center;"></div>Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.comtag:blogger.com,1999:blog-2760857886315929363.post-40692433658457233582008-11-24T01:25:00.000-08:002010-01-21T06:23:07.380-08:00How to install glassfish Java application serverI installed Glassfish application server few days ago, for the first time.<br />
Although it has no GUI installer and you have to do it all by typing in console window, it’s a quite easy thing to do…<br />
<br />
I needed new Java app server for some job to be done, and it was all up to me to decide which one to use…<br />
<br />
At the end, I decided to use either Glassfish or JBoss.<br />
<br />
Since I worked with glassfish that comes with NetBeans, and was very pleased with it , it was probably quite easy to guess that my choice is going to be glassfish…<br />
After all, glassfish is nothing else then Sun Java System Application Server , but without GUI installer and some extra options in it and, of course, without support…<br />
<br />
So, glassfish it is!<br />
<br />
There’s a lot of documentation on how to install and start it, and you can easily find out everything you need to do that…<br />
<br />
Since all the information that you need to know when installing this application server are on several locations on the internet, I will try to explain the entire process on how to install glassfish on windows so you don’t have to look for it on the net, hoping to save you some time…<br />
<br />
<br />
<span style="font-size: large;"><b>- Prerequisites</b></span><br />
<br />
In order to install glassfish, we need to have JDK 1.5 , or some newer version installed on the computer on which the glassfish will be running.<br />
Be aware: not just JRE , but JDK + JRE!<br />
<br />
So, install it and set all system variables ( JAVA_HOME, PATH and CLASSPATH ).<br />
<br />
<span style="font-size: large;"><b>- Installation</b></span><br />
<br />
Let’s start with downloading binaries.<br />
Go to the <a href="https://glassfish.dev.java.net/public/downloadsindex.html">https://glassfish.dev.java.net/public/downloadsindex.html</a> and download the latest stable version.<br />
<br />
The installation file is java archive. I downloaded<br />
<b>glassfish-installer-v2ur2-b04-windows.jar</b><br />
<br />
Let’s take this file, and place it where you want to install it.<br />
<br />
Tip: Wherever you place it, when you start the installation, the installer itself will create a “glassfish” folder on that location and place all the files in it…<br />
<br />
I don’t know why, but I like to install servers and all similar applications in root of C disk and not in “Program files”, so I’ll create a folder called “Sun” on the C disk , and copy glassfish-installer-v2ur2-b04-windows.jar in it , because I want my server to have a “C:\Sun\glassfish” path.<br />
<br />
We will start installation by typing <br />
<br />
<b>java –Xmx256m –jar glassfish-installer-v2ur2-b04-windows.jar</b><br />
<br />
It will first ask you to read ( scroll all the way down ) some licence agreement , or something like that. After you accept it, the installer will copy all the files to the “.\glassfish” folder.<br />
The installation is almost finished. There are just few more things that needs to be done.<br />
First of all, go to the <b><GLASSFISH_HOME>\lib\ant\bin\ </b>and type<br />
<br />
<b>ant –f setup.xml </b><br />
<br />
or from within installation directory type<br />
<br />
<b>.\lib\ant\bin\ant –f setup.xml </b><br />
<br />
This way, we created a new domain: domain1.<br />
Before you do this, you can open it with some editor and change the default names and ports, but if there’s no special need to do it – just don’t . Install it with default settings.<br />
<br />
Now add the <b><GLASSFISH_HOME>\bin</b> folder to the environment variable “PATH” ( then restart console window) , and at this moment your glassfish is installed and you can start it by typing<br />
<br />
<b>asadmin start-domain domain1</b><br />
<br />
and stop it by typing<br />
<br />
<b>asadmin stop-domain domain1</b><br />
<br />
<b>BUT:</b><br />
<br />
We now have two problems:<br />
<br />
- Glassfish does not have any tool to help you create a windows service for it , and since it is an application server , we need to have it running as a windows service. Fortunately, glassfish has executable called appservService.exe which communicates with the windows service controller, and we’ll use it later…<br />
<br />
- Glassfish was developed using Java and therefore it uses JVM. But, when a user logs off - JVM turns off as well, and this is something we do not want to happen with our application server when the user that started it logs of…We need to control this.<br />
<br />
<br />
So, the solution for the first problem is provided to us by <i>Ryan de Laplante</i> , who made a <b>GlassfishSvc.jar</b> file that will help us create a windows service for glassfish server.<br />
Go to <a href="http://www.ryandelaplante.com/rdelaplante/entry/creating_a_windows_service_for">http://www.ryandelaplante.com/rdelaplante/entry/creating_a_windows_service_for</a><br />
and download this file.<br />
After you downloaded it, copy it to your installation folder ( in my case: “C:\Sun\glassfish\” ) and run it with<br />
<br />
<b>java –jar GlassfishSvc.jar –i</b><br />
<br />
First problem solved ;-)<br />
<br />
We will solve the second problem with <b>–Xrs</b> JVM option.<br />
<br />
Open <b><GLASSFISH_HOME>\domains\domain1\config\domain.xml</b> file and add the following line:<br />
<br />
<b><jvm-options>-Xrs</jvm-options></b><br />
<br />
to the part of the file that has many other <b><jvm-options>something…</b><b></jvm-options></b> tags…<br />
<br />
Now, as I red, many people reported that this doesn’t work on windows 2003 server, so if this didn.t help, go to <b><GLASSFISH_HOME>\lib\processLauncher.xml</b><br />
and add a line<br />
<br />
<b><sysproperty key=”-Xrs”/></b><br />
<br />
inside a<br />
<br />
<b><process name=”as9-server”> </b><br />
<br />
section.<br />
<br />
What I did first, I added a line to <b><GLASSFISH_HOME>\domains\domain1\config\domain.xml </b>, restarted a server and logged off, but the JVM turned off also. This didn’t work for me…<br />
<br />
Then, I tried second option, restarted a server, logged off - but it didn’t work as well…???<br />
<br />
Then, I restarted windows, (server started by itself because it’s now a windows service), logged of and everything worked well…<br />
If someone asks me which solution helped me – I would tell him “I really don’t know, and I don’t care…”<br />
<br />
<br />
So, that’s it!<br />
Now you have a glassfish application server installed, you have a windows process for it and your JVM won’t turn off causing the server to shut down as well when you log off, and that is all we needed…<br />
<br />
I hope this text will help someone…<br />
<br />
Good luck and enjoy your glassfish!Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com0tag:blogger.com,1999:blog-2760857886315929363.post-13917335126091637492008-11-20T01:45:00.000-08:002010-02-01T01:32:13.050-08:00Read and write to .properties and .ini filesIt is usual to store settings or properties of an application in some of these 5 known ways:<br />
<br />
- to DB<br />
- to XML<br />
- to .ini file<br />
- to .properties file<br />
- to registry<br />
<br />
My favorite are XML and .ini/.properties file.<br />
All of them has some kind of restrictions, and it’s really up to data type that application needs to save , and which programming language I’m using at that moment…<br />
<br />
If my application needs to read/save small number of information, without complex scheme of sections, then I always use .properties or .ini files.<br />
<br />
To be honest, first time I used ( Java )class that works with .properties files, I was very surprised how easy is it to read/write settings. And all of that with small-size code, which is not usual in Java. ( Look at my earlier blog about parsing a document in PHP and Java : <a href="http://devtalks.blogspot.com/2008/09/parsing-xml-php-vs-java_16.html">http://devtalks.blogspot.com/2008/09/parsing-xml-php-vs-java_16.html </a>)<br />
<br />
In Java, in order to work with .properties files, there’s a <span style="font-weight: bold;">Properties </span>class. Properties class extends HashTable , so we manipulate properties through the get and set methods.<br />
It’s quite easy and fun to work with it.<br />
Let’s say we have some file: <b>example.properties</b>, and it looks something like this:<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSLmgNB_LyTEZZumP239iCNYsc5GoIJUEqelRJMIZbxZMzT1tMuwB6_dzKOkyGp_d9YVZ_kN2jtSbfjUCHDVIB8om2szuuo9PwVhc-Epw5AVgryQWoA13pMfOLp0ZHQ5NQ92JOgoPJDm4/s1600-h/properties.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSLmgNB_LyTEZZumP239iCNYsc5GoIJUEqelRJMIZbxZMzT1tMuwB6_dzKOkyGp_d9YVZ_kN2jtSbfjUCHDVIB8om2szuuo9PwVhc-Epw5AVgryQWoA13pMfOLp0ZHQ5NQ92JOgoPJDm4/s400/properties.gif" /></a> </div><div style="text-align: left;">We could easily parse it like this:</div><div style="text-align: left;"></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqvFW4IdUxZBH41AiFGFm_DVsWpupipqRvWhJKP_l4GYTsUjkG6EUBdpaQ2WN37Ge723NGdJAYbDoe_GwHaSO6ASa1UeDJAoQX74FjUqj1ERtqR8mC8ZI_eT3qLouEADcJNBLeu9jJWK8/s1600-h/read_java.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqvFW4IdUxZBH41AiFGFm_DVsWpupipqRvWhJKP_l4GYTsUjkG6EUBdpaQ2WN37Ge723NGdJAYbDoe_GwHaSO6ASa1UeDJAoQX74FjUqj1ERtqR8mC8ZI_eT3qLouEADcJNBLeu9jJWK8/s400/read_java.gif" /></a> </div><div class="separator" style="clear: both; text-align: left;">or, write current properties in application into the file with:</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIVVmZZo06GmpQWxAL6HMojly0GK3LvIA56wAHuXP1zfMUV6EJhnk5stl74Xe7UaclyQM4345DfjQ0fAalrus1znG9rk8VEJ49aC5heNALsvUKWA9JzDzBskDqwNJxplp9aoSfvLoBo4M/s1600-h/write_java.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIVVmZZo06GmpQWxAL6HMojly0GK3LvIA56wAHuXP1zfMUV6EJhnk5stl74Xe7UaclyQM4345DfjQ0fAalrus1znG9rk8VEJ49aC5heNALsvUKWA9JzDzBskDqwNJxplp9aoSfvLoBo4M/s400/write_java.gif" /></a></div><div class="separator" style="clear: both; text-align: left;">If we write</div><br />
<blockquote>public static void main(String args[])<br />
{<br />
Main main = new Main();<br />
main.readProperties();<br />
}</blockquote><div class="separator" style="clear: both; text-align: left;"><br />
</div><br />
the result would be:<br />
<div class="separator" style="clear: both; text-align: center;"></div><br />
<blockquote>color= blue<br />
width= 150<br />
height= 100</blockquote><span style="color: white;">color= blue</span> <span style="color: white;">width= 150</span> <span style="color: white;">height= 100 </span><br />
The other way around, if we write<br />
<br />
<blockquote>public static void main(String args[])<br />
{<br />
Main main = new Main();<br />
main.saveProperties();<br />
}</blockquote><div class="separator" style="clear: both; text-align: left;"><br />
</div>the <b>example.properties</b> file would look like this:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidy9ejrgJpSo38uIGFmiSE-Iw1zikoD7iUgRf-Bu7r9er-PW7LMqd44Az7N6PEk5tDAwXzrPHW0aQzx3kyWo6Ts-MFwCW1IXKGc1eJ0ch3oDgS-c6Dc-Y5TyMt_E7efbWW3TLo-GXf6n0/s1600-h/properties2.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidy9ejrgJpSo38uIGFmiSE-Iw1zikoD7iUgRf-Bu7r9er-PW7LMqd44Az7N6PEk5tDAwXzrPHW0aQzx3kyWo6Ts-MFwCW1IXKGc1eJ0ch3oDgS-c6Dc-Y5TyMt_E7efbWW3TLo-GXf6n0/s400/properties2.gif" /></a> </div><div class="separator" style="clear: both; text-align: left;">but, as you can see, without any particular order among properties that we wrote.</div><br />
As I sad, I didn’t used to write something in Java with such small code size, and it feels great… :-)<br />
<br />
All of this reminds me of <span style="font-weight: bold;">TIniFile</span> class in Borland Builder, and it is very hard to catch up with BCB when it comes to simplicity ( in my opinion, that is…).<br />
<br />
Let’s take a look how we would do this in BCB. Ini files are very similar to .properties files. The difference is that .ini files have sections, and .properties doesn’t.<br />
<br />
<br />
Let’s make a test application:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrRPeOldjQjXVhkpt6old_3sJNS_nHlxOnp815BBUa8TDR9OU5JoxxWkwdh6r0jP4dRzEgalht6gHMYXksHem3TDmeLlowyNGDHdKiEl6O2jMzNptHv4nRx_tkbUIWp0I6fv7sVRs1szU/s1600-h/bcb.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrRPeOldjQjXVhkpt6old_3sJNS_nHlxOnp815BBUa8TDR9OU5JoxxWkwdh6r0jP4dRzEgalht6gHMYXksHem3TDmeLlowyNGDHdKiEl6O2jMzNptHv4nRx_tkbUIWp0I6fv7sVRs1szU/s400/bcb.gif" /></a> </div><div class="separator" style="clear: both; text-align: left;">and let’s say we have file <b>example.ini</b> with a "<i><b>data</b></i>" section, and is looks something like this:</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNTqeGOXk_3be-iUznj7Glz5zrRZKricXhlApXj71ndzX5iQW5iznUrdpUn5utPOjYF-Yjm3OW15IPvCcOE6Ev8kQItEAT9oPVYHvK9CTHFPu7I3d5GePJd98yg8DXI7xktiH5ZElHVkQ/s1600-h/ini.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNTqeGOXk_3be-iUznj7Glz5zrRZKricXhlApXj71ndzX5iQW5iznUrdpUn5utPOjYF-Yjm3OW15IPvCcOE6Ev8kQItEAT9oPVYHvK9CTHFPu7I3d5GePJd98yg8DXI7xktiH5ZElHVkQ/s400/ini.gif" /></a> </div><div class="separator" style="clear: both; text-align: left;">and we need to write these settings in appropriate Edits on the Form when someone starts the application. At exit, we need to overwrite properties in a file with those that are in these three Edits at that moment…</div><br />
First of all, we would need this line:<br />
<div style="text-align: center;"><blockquote><span style="color: #38761d;"><inifiles.hpp></inifiles.hpp></span><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-VVw__IWXCbJ397GUE9dTIAp_0Zgf-NWk47aHAs2UxPMyLG_6R01bHSoHwJlyELb_oW5K1qw8N1z_Hd4wxglcWw1jK79f3iIOV2M9W5xOlQrk4Jg7gwQ4344nCZQXQRa-fK3MK9zHb4A/s1600-h/include.gif" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5270679558206670802" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-VVw__IWXCbJ397GUE9dTIAp_0Zgf-NWk47aHAs2UxPMyLG_6R01bHSoHwJlyELb_oW5K1qw8N1z_Hd4wxglcWw1jK79f3iIOV2M9W5xOlQrk4Jg7gwQ4344nCZQXQRa-fK3MK9zHb4A/s400/include.gif" style="cursor: pointer; display: block; height: 50px; margin: 0px auto 10px; text-align: center; width: 247px;" /></a></blockquote></div><div class="separator" style="clear: both; text-align: left;"><br />
</div>Then, we could easily parse the document with:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSUP9nvqdLAjdGpueV-EK7TYOQPnt7kZ7aNan9ZY5c9BGrscya7AwgLWk8O3aAdA7SPlpaB00xy0GVyjjg_MqCtcAL-rMShQI__Tnh1jcTl_DQgg4hCspLqSGiqLVlnXOZTSjgPwPa-GA/s1600-h/read_bcb.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSUP9nvqdLAjdGpueV-EK7TYOQPnt7kZ7aNan9ZY5c9BGrscya7AwgLWk8O3aAdA7SPlpaB00xy0GVyjjg_MqCtcAL-rMShQI__Tnh1jcTl_DQgg4hCspLqSGiqLVlnXOZTSjgPwPa-GA/s400/read_bcb.gif" /></a> </div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">or, write current properties in application into the file with:</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPkIWGtR8XtcYALkCm2mKR25-L4splhHNnHO0hVgn0FyAkGTEp9Ip45hv6HSOomkWbUjxG3nFcBBCJH-CDj1dZTibKqo8FOvIb2xWKM9kpm6l5ZBt3LS_1fP6SUTqfTzbgjMgyE7Wa40c/s1600-h/write_bcb.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPkIWGtR8XtcYALkCm2mKR25-L4splhHNnHO0hVgn0FyAkGTEp9Ip45hv6HSOomkWbUjxG3nFcBBCJH-CDj1dZTibKqo8FOvIb2xWKM9kpm6l5ZBt3LS_1fP6SUTqfTzbgjMgyE7Wa40c/s400/write_bcb.gif" /></a> </div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">If we write a constructor and a FormClose event like this:</div><blockquote>__fastcall TForm1::TForm1(TComponent* Owner)<br />
: TForm(Owner)<br />
{<br />
Form1->ReadProperties();<br />
}<br />
//---------------------------------------------------------<br />
<br />
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)<br />
{<br />
Form1->SaveProperties();<br />
}</blockquote><div class="separator" style="clear: both; text-align: left;"><br />
</div>and we start the app, it will read properties from ini file, and show it.<br />
<div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnUMeraAcvVK-fTSoYqpkTz0zt1utS-pY8uZvV8WG8s53Q24NkQZnUrtZao7xPQzIIMl2N-y-bqzIC8t5nr8hr6mHXikInqPDE6NR4hwyEnAfgf9hu48YTVABtl2uGYXQ7sra1Mj5gXPU/s1600-h/run.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnUMeraAcvVK-fTSoYqpkTz0zt1utS-pY8uZvV8WG8s53Q24NkQZnUrtZao7xPQzIIMl2N-y-bqzIC8t5nr8hr6mHXikInqPDE6NR4hwyEnAfgf9hu48YTVABtl2uGYXQ7sra1Mj5gXPU/s400/run.gif" /></a> </div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">and , if we write some other values, then the FormClose event will write new values to the ini file, preserving the order that we wanted...</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgy250uOaVXxhES9zlX-4qsBXckTne3p-7I5KzMR7aPaCElvzzIcS4AcPpIDnzOmDcrO0ArdX6BXcF1iVbccYhFlHX18M4K0KzFaECw8-nljkA1hLVzKYbmzNB_maxtefyi8YVgTcuSGdI/s1600-h/ini2.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgy250uOaVXxhES9zlX-4qsBXckTne3p-7I5KzMR7aPaCElvzzIcS4AcPpIDnzOmDcrO0ArdX6BXcF1iVbccYhFlHX18M4K0KzFaECw8-nljkA1hLVzKYbmzNB_maxtefyi8YVgTcuSGdI/s400/ini2.gif" /></a> </div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;">So, you saw now how easy it is to save properties into these two formats. I hope you like it the way I do... </div><div style="text-align: center;"></div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div style="text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><br />
</div>Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com0tag:blogger.com,1999:blog-2760857886315929363.post-5630883409068044252008-11-18T01:43:00.000-08:002010-01-21T06:24:24.598-08:00Writing OS-independent JAVA codeOne of the best things about Java is the fact that it’s applications are OS independent.<br />
This means that you can write application on one OS, and run it on some completely different.<br />
<br />
We ought to thank to JVM for this. It is JVM that cares how things should be done on certain OS.<br />
<br />
When you say, for example:<br />
<br />
<blockquote>new Thread(new Runnable(){public void run(){System.out.println("Hi, I'm thread!");}}).start();<br />
</blockquote><br />
Different OS will create this new Thread , set it’s priority , execute it and do many other things on completely different way, but thanks to JVM Java developers do not have to care about these things...<br />
<br />
Another good example is file chooser. For example, windows and Solaris have different file chooser , and if you use it’s APIs to call it your code would look completely different, but in Java you don’t care about it. Code:<br />
<br />
<blockquote>JFileChooser jfilechooser = new JFileChooser();<br />
if (jfilechooser.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION)<br />
...<br />
</blockquote><br />
will work on windows, and on Linux, and on about any other OS that you can find JVM for it...<br />
<br />
But, there is always a "BUT..."!<br />
<br />
Yes, with Java and it’s JVM over 90% of your apps will work on any OS that has JVM for it, but there are some rules that you must stick to when developing app that will run on different OSs.<br />
<br />
These are mostly trivial things, but enough to make your app not working correctly on a different OS.<br />
<br />
These are some of the most common:<br />
<br />
<b>-Using "/" or "\" instead of System.getProperty("file.separator")</b>. Different operating systems has different file separators. So, if you don’t know on which OS your app will run on, it is wise that instead of using, for example,<br />
<br />
String some_path = ".\\some_file.txt";<br />
<br />
you use<br />
<br />
String some_path = "." + System.getProperty("file.separator") + "some_file.txt";<br />
<br />
<br />
<b>-Using absolute, instead of relative path</b>. It is wise to use relative instead of absolute path because different OS have different file paths! For example, "c:\\some_file.txt" doesn’t mean anything on some linux, but "." + System.getProperty("file.separator") + "some_file.txt" , for example, certainly does!<br />
<br />
<br />
<b>-Using sockets on port < 1023</b>. Be aware that on some operating system ( for example linux ) only special users ( root) can use ports smaller than 1023. It is very wise to use port > 1023 if you can...<br />
<br />
<br />
<b>-It is wise to use System.getProperty("line.separator") instead of "\n" at the end of the line when writing something to files.</b><br />
<br />
<br />
<b>-Using OS-specific command when executing OS commands. </b><br />
Process process = Runtime.getRuntime().exec(command); can be very convenient , but be aware that different operating systems have different commands!<br />
<br />
<br />
<b>-Mixing letter case when working with files and folders</b>. This is very common problem. Many developers that use windows just forget that other OS are case-sensitive. So, in linux , if you try to read from file<br />
"." + System.getProperty("file.separator") + "some_file.txt"<br />
and that file is realy a "Some_file.txt" or , for example, "Some_file.TXT" you wan’t be able to read it, and your app will not work correctly...<br />
<br />
And the last ( and probably the least ):<br />
<b>-You probably will never create so many threads so that your OS will not be able to process them all,</b> but if you are using some older OS, or create very very large number of threads, different OS will act differently because not all OS have the same limitation for maximum number of active threads at the same time ( native threads, not green threads )<br />
<br />
<br />
These are just some of the rules you should stick to, if you want your app to really work the same way on different operating systems. No matter how trivial they are, people often forget about it...Darko Kalinichttp://www.blogger.com/profile/02177827287463278305noreply@blogger.com