Import a Controller in CakePHP

If you want to access some predefined controller in another controller in CakePHP. You can do this as explained in following example.

<?php
App::import('Controller', 'Events');
class HomesController extends AppController {
	var $name = 'Homes';
	var $Events;
	function beforeFilter() {
		$this->Events =& new EventsController();
		$this->Events->constructClasses();
	}
	function index() {
		$this->Events->index();
	}
}
?>

Model without Table in CakePHP

This is explained in following example

<?php
class ModelWithoutTable extends AppModel {
    var $useTable = false;
}
?>

Controller without Model in CakePHP

In some cases you may need to have a controller without its own model. This might be because you are using other models. You can do this by using an empty array.

<?php
class HomesController extends AppController {
	var $name = 'Homes';
	var $uses = array(); // Don't use Home Model
	function index() {

	}
}
?>

Changing default session timeout value in tomcat

Default session timeout value in tomcat is 30 minutes. To set new session timeout value edit web.xml file and add following lines.

    <session-config>
      <session-timeout>xy</session-timeout>
    </session-config>

xy is new session timeout value in minutes. Also don’t forget to restart tomcat.

Starting tomcat in debug mode – Linux

To start tomcat in debug mode, you need to set JPDA_TRANSPORT=dt_socket and JPDA_ADDRESS=9000 environment variable. To set these variable for a session only, open command prompt and run following commands

export CATALINA_HOME=/home/xyz/opt/tomcat
export JPDA_TRANSPORT=dt_socket
export JPDA_ADDRESS=9000

now start tomcat using following command

$ %CATALINA_HOME%/bin/catalina.sh jpda start

Setting this variable in your personal ~/.bashrc file has the advantage that it will always be set (for you, as a user) each time you log in or reboot the system. To do so, open ~/.bashrc in a text editor (or create the file if it doesn’t already exist) and insert the following line anywhere in the file

export CATALINA_HOME=/home/xyz/opt/tomcat
export JPDA_TRANSPORT=dt_socket
export JPDA_ADDRESS=9000

Save and close .bashrc.
You must logout and login again to make your change take effect. or source your .bashrc file to make your change take effect for the current session

$ source ~/.bashrc

Changing project type form general to java in eclipse

You have a project, which is basically a java project but during checking out the project or creating a new project, you didn’t selected type of project as java. You are stuck now as there is no option to change it to java type in eclipse UI.
You can change type of project by modifying.projectfile, located in the root directory of your project. Open .project file in any text editor and search for text “natures”. You’ll see an empty natures node.

<natures>
</natures>

Change this value to

<natures>
        <nature>org.eclipse.jdt.core.javanature</nature>
</natures>

See Servlet Spec 2.3, section 9.7.2

If you are getting warnings or errors related with Servlet Specification, version 2.3, section 9.7.2. It means that you are trying to override web container’s implementation classes from your applications classes.
Servlet specification 2.3 section 9.7.2 says this clearly

The classloader that a container uses to load a servlet in a WAR must allow the developer to load any resources contained in library JARs within the WAR following normal J2SE semantics using getResource. It must not allow theWAR to override J2SE or Java servlet API classes. It is further recommended that the loader not allow servlets in theWAR access to the web container’s implementation classes. It is recommended also that the application class loader be implemented so that classes and resources packaged within the WAR are loaded in preference to classes and resources residing in container-wide library JARs.

You can get away from these warnings by doing one of the following

1. server-api.jar is needed to compile an application and is not required in application war to run application as container already have this file. You must remove this file from WEB-INF/lib.

2. It can be because of other jar files that are bundled with container. e.g. j2ee.jar. You need to remove this file from your application’s lib directory.

In tomcat 6, $CATALINA_HOME/lib/ contains all the jar file which one should not override with those of application’s jar. tomcat 5 has these jars in $CATALINA_HOME/common/lib folder.