<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>My IT-blog &#187; server management</title>
	<atom:link href="http://dev.eek.be/tag/server-management/feed/" rel="self" type="application/rss+xml" />
	<link>http://dev.eek.be</link>
	<description>IT knowledge exchange</description>
	<lastBuildDate>Fri, 04 Jun 2010 05:34:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>servletconfig vs servletcontext</title>
		<link>http://dev.eek.be/2009/10/servletconfig-vs-servletcontext/</link>
		<comments>http://dev.eek.be/2009/10/servletconfig-vs-servletcontext/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 20:15:58 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[server management]]></category>
		<category><![CDATA[servlet]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=80</guid>
		<description><![CDATA[In this little blogpost, I&#8217;ll try to explain the differences between ServletConfig and ServletContext and when you can use them into a Java Web Application. ServletConfig ServletContext Access deploy-time servlet parameters Access web application parameters One per servlet One per web application ServletConfig ServletConfig is actually very simple. Like stated above, you can retrieve parameters [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://dev.eek.be/wp-content/uploads/2009/10/java2.jpg" alt="java2" title="java2" width="300" height="225" class="aligncenter size-full wp-image-151" />
<p>In this little blogpost, I&#8217;ll try to explain the differences between ServletConfig and ServletContext and when you can use them into a Java Web Application.</p>
<table cellpadding="2" cellspacing="0" border="1">
<tr>
<td><b>ServletConfig</b></td>
<td><b>ServletContext</b></td>
</tr>
<tr>
<td>Access deploy-time servlet parameters</td>
<td>Access web application parameters</td>
</tr>
<tr>
<td>One per servlet</td>
<td>One per web application</td>
</tr>
</table>
<p><b>ServletConfig</b></p>
<p>ServletConfig is actually very simple. Like stated above, you can retrieve parameters for the servlet which are set at deployment time.<br />
I&#8217;ll explain this with a very simple example.
</p>
<p>
If you have created a servlet with the name &#8220;MyServlet&#8221; you can add the following 2 variables into the servlet:</p>
<pre class="prettyprint" lang-xml>
    &lt;servlet&gt;
         &lt;servlet-name&gt;MyServlet&lt;/servlet-name&gt;
         &lt;servlet-class&gt;servlets.MyServlet&lt;/servlet-class&gt;
         &lt;init-param&gt;
             &lt;param-name&gt;variable1&lt;/param-name&gt;
             &lt;param-value&gt;I'm var1&lt;/param-value&gt;
         &lt;/init-param&gt;
         &lt;init-param&gt;
             &lt;param-name&gt;variable2&lt;/param-name&gt;
             &lt;param-value&gt;I'm var2&lt;/param-value&gt;
         &lt;/init-param&gt;
     &lt;/servlet&gt;
     &lt;servlet-mapping&gt;
         &lt;servlet-name&gt;MyServlet&lt;/servlet-name&gt;
         &lt;url-pattern&gt;/MyServlet&lt;/url-pattern&gt;
     &lt;/servlet-mapping&gt;
</pre>
</p>
<p>
You can retrieve variable2 with the following code:</p>
<pre class="prettyprint" lang-java>
getServletConfig().getInitParameter("variable2");
</pre>
</p>
<p>
Retrieve all the variables of the servlet and loop over them:</p>
<pre class="prettyprint" lang-java>
Enumeration allvars = getServletConfig().getInitParameterNames();
while (allvars.hasMoreElements()) {
     String next = (String) allvars.nextElement();
     out.println(next + " has the value " + getServletConfig().getInitParameter(next));
}
</pre>
</p>
<p>
It&#8217;s also possible to retrieve the servlets name through getServletconfig</p>
<pre class="prettyprint" lang-java>
out.println("The name of the servlet is: " + getServletConfig().getServletName());
</pre>
</p>
<p><b>ServletContext</b></p>
<p>
ServletContext can be used to retrieve application-wide parameters, get serverparameters and store/retrieve/remove application-wide attributes.
</p>
<p>It is possible to call the ServletContext right on or through the ServletConfig. Both are the same so you can choose between them.</p>
<pre class="prettyprint" lang-java>
if (getServletContext().equals(getServletConfig().getServletContext())) {
       out.println("both calls retrieve the same Context");
}
</pre>
</p>
<p>
Just like with ServletConfig, you can set parameters in the Deployment Descriptor. They are initialized on compile time. It&#8217;s not possible to remove or add them on runtime.</p>
<pre class="prettyprint" lang-xml>
&lt;context-param&gt;
        &lt;param-name&gt;variable3&lt;/param-name&gt;
        &lt;param-value&gt;Im var 3&lt;/param-value&gt;
&lt;/context-param&gt;
</pre>
<p>And call them in your servlet just like the ServletConfig parameters:</p>
<pre class="prettyprint" lang-java>
getServletContext().getInitParameter("variable3")
</pre>
</p>
<p>
Unlike ServletConfig, ServletContext can work with attributes. These are parameters or objects which you can set into the servlet and retrieve in every other servlet of your Web Application:</p>
<pre class="prettyprint" lang-java>
getServletContext().setAttribute("test", "I'm an application-wide String");
..
out.println(getServletContext().getAttribute("test"));
..
getServletContext().removeAttribute("test");
</pre>
</p>
<p>
I&#8217;ll end this little short tutorial with an example of how you can retrieve serversettings through the Context:</p>
<pre class="prettyprint" lang-java>
out.println(getServletContext().getContextPath());
out.println(getServletContext().getMajorVersion());
out.println(getServletContext().getRealPath(""));
out.println(getServletContext().getServerInfo());
</pre>
</p>
<p>If there are any more questions, just shoot them <img src='http://dev.eek.be/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2009/10/servletconfig-vs-servletcontext/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use multiple instances of Webalizer on one server</title>
		<link>http://dev.eek.be/2009/09/use-multiple-instances-of-webalizer-on-one-server/</link>
		<comments>http://dev.eek.be/2009/09/use-multiple-instances-of-webalizer-on-one-server/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 21:36:23 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[server management]]></category>
		<category><![CDATA[webalizer]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=34</guid>
		<description><![CDATA[In most of the cases, there is more than just one website on a server. Though, it is very important that you can measure the stats of all the websites separately. I&#8217;ll tell you in a few lines how you can achieve this with webalizer. This tutorial is tested with Webalizer on Ubunty but I [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-36" title="webalizer" src="http://dev.eek.be/wp-content/uploads/2009/09/webalizer.png" alt="webalizer" width="521" height="267" /></p>
<p>In most of the cases, there is more than just one website on a server.<br />
Though, it is very important that you can measure the stats of all the websites separately.<br />
I&#8217;ll tell you in a few lines how you can achieve this with <a href="http://www.mrunix.net/webalizer/" target="_blank">webalizer</a>.</p>
<p><span id="more-34"></span></p>
<p>This tutorial is tested with Webalizer on Ubunty but I presume it will work almost the same way in other distros.</p>
<p>First of all you have to install webalizer on your system.</p>
<pre class="prettyprint">
sudo apt-get install webalizer
</pre>
<p>After installation of webalizer, the configurationfiles are per default stored in /etc/webalizer.<br />
Move to that directory and make a copy of the config-file.</p>
<pre class="prettyprint">
sudo cp webalizer.conf MySiteName.conf
</pre>
<p>When the copy is created you have to open it in your favorite editor (I use vim)</p>
<pre class="prettyprint">
sudo vim MySiteName.conf
</pre>
<p>Scroll down till you find the LogFileattribute and change it to the accesslogfile of MySiteName.<br />
You also have to tell the script where the outputfiles will be stored. This is normally a place which is accessible by the browser.</p>
<pre class="prettyprint">
LogFile /www/mysite/logs/access.log
OutputDir /www/mysite/public_html/webalizer
</pre>
<p>These are the only 2 parameters which you have to change. You can scroll through the rest of the file and make changes towards your preferences.</p>
<p>All is done now so you can run webalizer with the new configuration file</p>
<pre class="prettyprint">
webalizer -c /etc/webalizer/MySiteName.conf
</pre>
<p>Webalizer will run and should be accessible through your webbrowser.<br />
Obviously, it would kinda suck if you have to run the webalizerscript every time you want to see the stats so we gonna make a cron which will run the script every hour</p>
<pre class="prettyprint">
crontab -e
</pre>
<p>And fill in:</p>
<pre class="prettyprint">
0 * * * * webalizer -c /etc/webalizer/MySiteName.conf
</pre>
<p>Voila, all done <img src='http://dev.eek.be/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2009/09/use-multiple-instances-of-webalizer-on-one-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
