Saturday, May 17, 2008

Servlets

  1. Servlets are simply .class files, i.e., compiled .java files.
  2. Servlet files are stored in the WEB-INF/classes subdirectory of the main web application directory. In this case the .class files for the examples web app is stored in %TOMCAT_HOME%/webapps/examples/WEB-INF/classes.
  3. So when the user requests
    http://localhost:8080/examples/servlet/HelloWorldExample
    Tomcat runs
    %TOMCAT_HOME%/webapps/examples/WEB-INF/classes/HelloWorldExample.class



  • Create a folder inside webppas of Tomcat server (star, for example)
  • "\WEB-INF\classes" is the folder to keep Servlet class files
  • 'web.xml' is saved in the '/WEB-INF' folder
  • Compile command
javac -cp %CATALINA_HOME%\lib\servlet-api.jar TestServlet.java


The url to access the servlet , after starting Tomcat server

http://localhost:8080/star/TestServlet

------------------------------------------------
1- must run Tomcat server then try http://localhost:8080 to verify it works
2- There is a specific structure for the files
/webapps/myApp/WEB-INF/classes/ will contain java classes
/webapps/myApp/WEB-INF/src/ will contain the source
/webapps/myApp/script/ will contain other script code

3-assign your servlet class to a package, for example at the beginning of the Java file
package org.oats;


4- Need to tell were the servlets resides (the path classes) using web.xml
which is saved in /webapps/myApp/WEB-INF/web.xml



Ontology
Ontology


org.oats.OntologyServlet



Finally, again in the web.xml file, add:


Ontology


/Ontology



That says "When you see the URL /Ontology, call the Servlet name "Ontology",
which is mapped to the 'org.oats.OntologyServlet' class".


5- the two main methods to implement in servlets are doGet and doPost

Monday, May 12, 2008

Mod Python (using python in the web)

Mod_python is an Apache module that embeds the Python interpreter within the server. With mod_python you can write web-based applications in Python that will run many times faster than traditional CGI and will have access to advanced features such as ability to retain database connections and other data between hits and access to Apache internals.

ModPython

How to install:

1-Download binaries for windows
2-run the installer (must have installed Python and Apache server , with same versions compatabile with the version of modPython)
3- Choose place of where Python is installed
4- Add the line into conf/httpd.conf
LoadModule python_module modules/mod_python.so

5- Add the following as a new Directory tags in the file conf/httpd.conf (Directory is a tag < >)

Directory "E:\moodle\moodle\PythonTest"
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On
/Directory

Now to test it create a file with .py inside the root of apache, it will execute the function with the name handler.

To Work With forms

PythonHandler mod_python.publisher

It will pass the form into the the .py file into the function name index(), with the same names of the fields.

Thursday, May 8, 2008

How to use protege OWL API in Eclipse

1-Create Java Project
2-Goto Project->Properties-> Java Build Paths

Libraries tab, click add external JARS and go
inside Protege directory ->select all jar files.
inside Protege directory ->Plugins inside (edu.stanford.smi.protegex.owl) select all jar files.
Also
Select protege.api from /protege/


in Java code

import edu.stanford.smi.protegex.owl.ProtegeOWL;
import edu.stanford.smi.protegex.owl.model.*;

Friday, April 18, 2008

Tomcat With Eclipse

1- Install Eclipse JEE
2- Windows -> Preferences -> Java -> Installed JRE (must be the JDK folder)
3- Download “Sysdeo Tomcat Lanucher” and unzip the folder into “Eclipse\Plugins”
4- In the command line “eclipse –clean”
5- Window -> Preference -> Tomcat (Select version and home folder of Tomcat)

Thursday, April 17, 2008

Installing Tomcat

Most people will just want to download the preconfigured Tomcat version, set JAVA_HOME and CLASSPATH, and they are done.

2. Set the JAVA_HOME Variable

Next, you must set the JAVA_HOME environment variable to tell Tomcat where to find Java. Failing to properly set this variable prevents Tomcat from compiling JSP pages. This variable should list the base JDK installation directory, not the bin subdirectory. For example, on almost any version of Windows, if you use JDK 1.5_08, you might put the following line in your C:\autoexec.bat file.

set JAVA_HOME=C:\Program Files\Java\jdk1.5.0_08


On Windows XP, you could also go to the Start menu, select Control Panel, choose System, click on the Advanced tab, press the Environment Variables button at the bottom, and enter the JAVA_HOME variable and value directly. On Windows 2000 and NT, you do Start, Settings, Control Panel, System, then Environment. However, you can use C:\autoexec.bat on those versions of Windows also (unless a system administrator h as set your PC to ignore it).

3. Set Your CLASSPATH

Since servlets and JSP are not part of the Java 2 platform, standard edition, you have to identify the servlet classes to the compiler. The server already knows about the servlet classes, but the compiler (i.e., javac) you use for development probably doesn't. So, if you don't set your CLASSPATH (either via an environment variable, an operating system setting, or an IDE setting), attempts to compile servlets, tag libraries, filters, Web app listeners, or other classes that use the servlet and JSP APIs will fail with error messages about unknown classes. Here are the standard Tomcat locations:

* install_dir/common/lib/servlet-api.jar
* install_dir/common/lib/jsp-api.jar

You need to include both files in your CLASSPATH.

Now, in addition to the servlet JAR file, you also need to put your development directory in the CLASSPATH. Although this is not necessary for simple packageless servlets, once you gain experience you will almost certainly use packages. Compiling a file that is in a package and that uses another class in a user-defined package requires the CLASSPATH to include the directory that is at the top of the package hierarchy. In this case, that's the development directory I just discussed. Forgetting this setting is perhaps the most common mistake made by beginning servlet programmers!

Finally, you should include "." (the current directory) in the CLASSPATH. Otherwise, you will only be able to compile packageless classes that are in the top-level development directory.

Here are two representative methods of setting the CLASSPATH. They assume that your development directory is C:\Servlets+JSP. Replace install_dir with the actual Tomcat installation path (e.g., C:\apache-tomcat-6.0.10). Also, be sure to use the appropriate case for the filenames, and enclose your pathnames in double quotes if they contain spaces.

Any Windows Version from Windows 98/Me Onward. Use the autoexec.bat file.

* Sample code: (Note that this all goes on one line with no spaces--it is broken here only for readability.)
set CLASSPATH=.;
C:\Servlets+JSP;
install_dir\common\lib\servlet-api.jar;
install_dir\common\lib\jsp-api.jar
* Sample file to download and modify: autoexec.bat

Note that these examples represent only one approach for setting the CLASSPATH. Many Java integrated development environments have global or project-specific settings that accomplish the same result. But these settings are totally IDE-specific and won't be discussed here. Another alternative is to make a .bat file or ant build script whereby -classpath ... is automatically appended onto calls to javac.

Windows NT/2000/XP. You could use the autoexec.bat file as above, or you can use system settings. On WinXP, go to the Start menu and select Control Panel, then System, then the Advanced tab, then the Environment Variables button. On Win2K/WinNT, go to the Start menu and select Settings, then Control Panel, then System, then Environment. Either way, enter the CLASSPATH value from the previous bullet.

Autoexec.bat
set PATH="C:\Program Files\Java\jdk1.5.0_08\bin";%PATH%
set JAVA_HOME=C:\Program Files\Java\jdk1.5.0_08
set CLASSPATH=.;C:\apache-tomcat-6.0.10\lib\servlet-api.jar;C:\apache-tomcat-6.0.10\lib\jsp-api.jar;C:\apache-tomcat-6.0.10\lib\el-api.jar;C:\Servlets+JSP;..;..\..

Tuesday, April 15, 2008

How to Import .SQL Dump File into MySQL

This tutorial goes through the steps of how to import a SQL script file into a MySQL database. The computer setup I'm using for this step-by-step guide includes Windows XP Professional and MySQL 5.0, however you should also be able to use this same process for importing SQL dump files with MySQL 4.1.

1. Open the MySQL Command Line Client and type in your password, and press Enter to login. See Figure 1.

2. Change to the database you want to use for importing the .sql file data into. Do this by typing

USE your_database_name

and press Enter. See Figure 2.

For example the full line would look like: mysql> USE myTestDatabase

3. Now locate the .sql file you want to execute. For instance if the file is located in the main local C: drive directory and the .sql script file name is currentSqlTable.sql, (See Figure 3) you would type the following:

\. C:\currentSqlTable.sql

and press Enter to execute the sql script file.

For example, the full line would look like: mysql> \. C:\ currentSqlTable.sql

Note: You can use either the source or \. command to execute a SQL script file. For instance:

mysql> source file_name
mysql> \. file_name

Saturday, April 12, 2008

Ideas about tagging

Using Moodle we can add new features only by adding new modules (activities) or blocks. To add the new tagging feature for all facilities in Moodle this is not possible using these 2 features. Because currently tagging is only related with textfields defined from some place related to the tag defined (interests, blogs). We need to have a more intuitive way for adding new tags for every component in Moodle and to have it saved in some repository.

What happened when the user click on the tag button (delicious) on the tool bar of the explorer, we need to do similar thing from a link from inside the web page. This type of tagging will be only for the whole web page, but in order to tag specific parts of the web page we need something to specify that (keystroke when we reach specific part of the page, new menu item when mouse is clicked ). Remember that whatever you tag it will be one of two things (whole page, specific anchor link in the page).