Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-dev] How does a minimal Servlet 3.0 web application look like?

looks like I replied to your post on stackoverflow first so read my response on there

also, our documentation that you are reading through there is a complete organization and rewriting of lots of other documentation so gaps in it like you noted already are good to know about...please keep giving feedback on that, the whole beginner quickstart section is almost entirely a new effort for beginners to understand jetty, historically it has been used by people who already know the basics and are seeking our performance and architectural design...so we are working to bridge the gap :)

cheers,
jesse 

--
jesse mcconnell
jesse.mcconnell@xxxxxxxxx



On Fri, Dec 14, 2012 at 2:24 AM, Cubic <Hannes.Steffenhagen@xxxxxxxxxxxxxx> wrote:
I'm trying to create a Servlet 3.0 Web application. I've never done anything
like this before (well I've looked a bit into rails and noir, but right now
I'm required to use a pure java solution as this is for a university
project).

Basically I read that with Servlet 3.0 I just need the @WebServlet
annotation, and to implement Servlet in one way or another to make something
a servlet, without further configuration by means of web.xml or anything
like that.

That's all great and all, except it doesn't work. I wrote something like
this:

package de.swt1321.servlet;

import java.io.OutputStream;
import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name="HelloWorldServlet",value="/hello", loadOnStartup=1)
public class ServletTest extends HttpServlet {
    private static final java.nio.charset.Charset UTF8 =
java.nio.charset.Charset.forName("UTF8");

    @Override
    public void doGet(HttpServletRequest req,
                          HttpServletResponse res) throws ServletException,
IOException
    {
        byte[] HTML = "<html><head><title>Hello World!</title></head><body>
IT FUCKING WORKED!
</body></html>".getBytes(UTF8);
        res.setStatus(HttpServletResponse.SC_OK);
        res.setHeader("content-type","text/html;charset=utf8");
        res.setIntHeader("content-length",HTML.length);
        OutputStream os = res.getOutputStream();
        os.write(HTML);
        os.flush();
    }
}


And put that under WEB-INF/classes in a war file, and then putting that war
file in my webapps folder in Jetty (I'm using Jetty  9).

I only get static html content though (I put an index.html file under the
root of my war), and get 404 on /hello, which I'd have suspected to give me
the response I create in that servlet. Please tell me what I'm doing wrong
and how I can make it be less wrong.



--
View this message in context: http://jetty.4.n6.nabble.com/How-does-a-minimal-Servlet-3-0-web-application-look-like-tp4959725.html
Sent from the Jetty Dev mailing list archive at Nabble.com.
_______________________________________________
jetty-dev mailing list
jetty-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-dev


Back to the top