Vaadin URL

How a Vaadin app configure it as one single servlet with the url-pattern /*, be able to access objects like http://localhost:8080/parts/myapplet.jar

The problem I run into is that I want to add an applet, and right now I believe I should create a generic web app to put the applet’s jars

BTW Vaadin is really nice!

Appreciatte your thought on this regards

web.xml

parts
/*

There are, as usual, several approaches:

[b]

  1. Serve static content separately
    [/b]
    That is: not via Vaadin

You can make Tomcat (and others, but YMMV) serve your folder by adding this to your web.xml:

<servlet-mapping>
		<servlet-name>default</servlet-name>
		<url-pattern>/parts/*</url-pattern>
</servlet-mapping>

BUT instead you might want to make the pattern /VAADIN/* and put your static stuff PLUS all the stuff from the VAADIN folder in the jar there (or make one /parts and one /VAADIN). This way you’ll serve all the static content w/o hitting the vaadin servlet at all.

FINALLY in a production setup, you should have some other server (not tomcat) serve static content - e.g Apache or Nginx, which are particularly good at serving static content.


2. Use Resources

a) put jar in theme and use ThemeResource
b) put jar among class-files and use ClassResource
c) put jar somewhere else accessible by the servlet and use FileResource.
Oh, and StreamResource can also be used.
See
The Book about resources
.

In your case I’d go with 1, though 2 might be more suitable in some other cases.

Best Regards,
Marc

You could add something as simple as a JSP page to host the applet, and then your servlet declarations and mapping would look like this:

    <servlet>
        <servlet-name>MyVaadinApp</servlet-name>
        <servlet-class>com.example.MyApp</servlet-class>
        <init-param>...</init-param>
    </servlet>

    <servlet>
        <servlet-name>myapplet</servlet-name>
        <jsp-file>myapplet.jsp</jsp-file>
    </servlet>

    <servlet-mapping>
        <servlet-name>MyVaadinApp</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>myapplet</servlet-name>
        <url-pattern>/myapplet</url-pattern>
    </servlet-mapping>

To put it another way, you don’t need a whole other web application. You can just map a url pattern to another servlet or JSP page. Whatever URL the user goes to, the most specific matching URL pattern wins.

Cheers,
Bobby