<?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>Developer Papercuts &#187; Servlet</title>
	<atom:link href="http://www.vogella.de/blog/category/servlet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vogella.de/blog</link>
	<description>Tips around Eclipse and Android programming</description>
	<lastBuildDate>Wed, 08 Feb 2012 17:31:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>The Servlet within &#8211; Servlet creates Javascript coding</title>
		<link>http://www.vogella.de/blog/2009/07/04/servlet-javascript/</link>
		<comments>http://www.vogella.de/blog/2009/07/04/servlet-javascript/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 17:41:53 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Servlet]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=395</guid>
		<description><![CDATA[The following explains how to create Javascript output with a servlet and how to include this Javascript into a static HTML page. The generated Javascript code will again write some text into the HTML pages.

For this tutorial you need to use Eclipse and know how to develop servlets with Eclipse.

See  Servlet and JSP ...]]></description>
			<content:encoded><![CDATA[<p>The following explains how to create Javascript output with a servlet and how to include this Javascript into a static HTML page. The generated Javascript code will again write some text into the HTML pages.</p>
<p>For this tutorial you need to use Eclipse and know how to develop servlets with Eclipse.</p>
<p>See <a href="http://www.vogella.de/articles/EclipseWTP/article.html"> Servlet and JSP development with Eclipse </a><br />
in case you need an introduction. </p>
<p>Create a new dynamic Web project &#8220;de.vogella.wtp.javascript&#8221;. Create a package &#8220;de.vogella.wtp.javascript&#8221;.</p>
<p>Create a new servlet &#8220;JavaScriptServlet&#8221; in your package. The URL mapping should be done to /JSCounter.js.</p>
<p><a href="http://www.vogella.de/blog/wp-content/uploads/2009/07/jscounter10.gif"><img src="http://www.vogella.de/blog/wp-content/uploads/2009/07/jscounter10.gif" alt="jscounter10" width="491" height="480" class="alignnone size-full wp-image-406" /></a></p>
<pre>

package de.vogella.wtp.javascript;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.concurrent.atomic.AtomicLong;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class JavaScriptServlet
 */
public class JavaScriptServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private AtomicLong counter = new AtomicLong(0);   // We start with zero

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession(true);
		// Set the session valid for 2 secs
		session.setMaxInactiveInterval(1);
		response.setContentType("text/plain");
		PrintWriter out = response.getWriter();

		if (session.isNew()) {
			counter.incrementAndGet();
		}
		String s = "br.writeln(\"This site has been accessed "+ "<B>" + counter.get() +"</B><BR>"+"\");";
		out.println("var br=document;");
		out.println(s);
	}

}
</pre>
<p>Run the servlet, as a result the system should give you a popup with a file to save.</p>
<p>Create now a static HTML page &#8220;index.html&#8221; under WebContent which calls the servlet. Example can be download from here.</p>
<p><a href='http://www.vogella.de/blog/wp-content/uploads/2009/07/index.html'>Right click to download this file</a></p>
<p>This HTML page will call the servlet. The HTML page will then receive the response of the servlet and interprets the response as JavaScript. Open this HTML page in a browser while your servlet is running to display the counter.</p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/07/04/servlet-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse WTP &#8211; Deployment location of the local Tomcat</title>
		<link>http://www.vogella.de/blog/2009/04/08/eclipse-wtp-deployment-location-of-the-local-tomcat/</link>
		<comments>http://www.vogella.de/blog/2009/04/08/eclipse-wtp-deployment-location-of-the-local-tomcat/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 08:53:58 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Servlet]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=242</guid>
		<description><![CDATA[If you ever wondered where Eclipse WTP deploys your web application during development (if you use the local server option in Eclipse) you find the result of your deployment under:

Workspace-&#62; .metadata -&#62; .plugins\org.eclipse.wst.server.core\ and then tmp\wtpwebapps\project name

Update for Eclipse 3.5 (wtpwebapps in the path seems to be new)]]></description>
			<content:encoded><![CDATA[<p>If you ever wondered where Eclipse WTP deploys your web application during development (if you use the local server option in Eclipse) you find the result of your deployment under:</p>
<p>Workspace-&gt; .metadata -&gt; .plugins\org.eclipse.wst.server.core\ and then tmp[number]\wtpwebapps\project name</p>
<p>Update for Eclipse 3.5 (wtpwebapps in the path seems to be new)</p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/04/08/eclipse-wtp-deployment-location-of-the-local-tomcat/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

