Integrate Vaadin to an Existing JSP application/project

Hi, I am new to Vaadin. I tried searching the forum but I can’t seem to find what I am looking for.

I am new to programming and We have an existing project created using only JSP pages. There will be an enhancement on the project and I want to use vaadin in the enhancement. So I added the Vaadin library and web.xml attributes needed to the same project. However, when I tried to call the page from within the vaadin application, It will not display the page but instead it will only display my vaadin main window. I also try to run on server the existing page but it also redirects to the vaadin main window. Anything I need to do to add vaadin in my application and for me to call my existing pages created using JSP from within the vaadin application?

Thank you very much in advance!

Anybody? Please help. Thank you!

Not sure what the problem actually is, couldn’t quite follow your description, sorry. But it sounds a little bit like the Vaadin-servlet reacting on the content-root of your application and therefore there is a conflict between the JSPs and the Vaadin-servlet. Maybe you can show a little code and describe your setup?

I have an existing application before named myApp. When I haven’t integrated vaadin to it I can easily call any pages from my application using the URL like

http://localhost:8080/myApp/myJSPPage.jsp

Then I integrated vaadin

http://localhost:8080/myApp/ - brings me to my main vaadin window

From within vaadin window I have this Link that calls the myJSPPage.jsp. But instead of going to my existing application myJSPPage, it will only still display my existing main window but the url has been changed to this:

http://localhost:8080/myApp/myJSPPage.jsp

public class SVNInstallerPanel extends Panel {
public SVNInstallerPanel(URL url){
super(“SVN Installer”);
this.addStyleName(“AutosysSvnPanel”);
//AddAutosysButton addButton = new AddAutosysButton(this,url);
Link link = new Link(“SVN Installer”,
new ExternalResource(url+“myApp/myJSPPage.jsp”));
link.addStyleName(“svnInstallerLink”);
link.setIcon(new ThemeResource(“images/svnInstaller.png”));
this.addComponent(link);
this.setHeight(100, Sizeable.UNITS_PERCENTAGE);
}

}

Do I need to add something in the web.xml file to solve this issue? Thank you very much!

Well, I don’t have any experience with Vaadin inside a JSP-application, but I think your Vaadin-Servlet-Mapping in the web.xml is probably wrong, or rather a bit too loose. I guess you re using some wildcard-mapping like “/", which would simply match any URL underneath your Context-Root. Try to tighten that a bit by matching only a single URL underneath your Context-Root, for example “/myVaadinApp”. Remember that you then most probably also need an URL-matching for the widgetset-resources in "VAADIN/”.

This is easily fixed. You’ve mapped, I assume, /* to your Vaadin app. The URL http://localhost:8080/myApp/myJSPPage.jsp matches /* so you get your Vaadin app displayed. You would get the same result if you went to http://localhost:8080/myApp/abcdefg, http://localhost:8080/myApp/123456, etc.

You need a more specific matching url pattern in web.xml to show the JSP. First, a servlet entry declared for your JSP (JSPs are servlets, after all):

    <servlet>
        <servlet-name>MyJSP</servlet-name>
        <jsp-file>/myApp/myJSPPage.jsp</jsp-file>
    </servlet>

And a mapping:

    <servlet-mapping>
        <servlet-name>MyJSP</servlet-name>
        <url-pattern>/myApp/myJSPPage.jsp</url-pattern>
    </servlet-mapping>

Unfortunately, there’s no way in Java EE right now to specify a URL pattern with
excluded
URLs. That would be very useful when you want to map /* to an application but have some other directory like /static/* not get mapped to it (Tomcat has a built in servlet I think for this kind of thing, but it’s not as general as my idea of having excluded url patterns).

I just had to do something similar with my application, running at /*, and needed to include a servlet at another URL that forwards to a JSP that I keep in WEB-INF/jsps. It’s all fairly straightforward, but not obvious. Like many things, I’ve been meaning to blog about it. :slight_smile:

Cheers,
Bobby

Thanks Everyone. Actually, I just got back to this post, but I already saw another forum stating that web.xml mapping needs to be changed as suspected. Thank you again for your answers!

Two years later, this was helpful. I wrote a nice Vaadin app, and then my boss wanted me to throw the company login page on it: a JSP. I struggled for a whole day in trying to integrate a JSP login page with Spring Security and Spring-MVC (controller to take the login and check against database and then redirect to launch the Vaadin app). I ready many forum and blog posts with only obliquely illuminating tips. I was plagued with redirect loops, 404s, etc. As Mr. Bissett said, the solution was not obvious to me but it turned out to be straightforward. One of the most befuddled moments in my eight years of programming.

I ended up doing this in Spring context-security.xml:

<http auto-config="true" use-expressions="true" access-denied-page="/accessDenied.jsp"> <intercept-url pattern="/home.do" access="isAuthenticated()" /> <intercept-url pattern="/**" access="isAuthenticated()" /> <form-login login-page="/jsp/login.jsp" authentication-failure-url="/login.jsp?login=0" default-target-url="/home.do" /> <logout logout-success-url="/login.jsp?login=-1" delete-cookies="JSESSIONID" /> <remember-me /> <session-management invalid-session-url="/login.jsp?login=-2" /> </http> And this in web.xml:

...
<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
                   /WEB-INF/spring/ea-context.xml
                   /WEB-INF/spring/ea-context-jndi.xml
                   /WEB-INF/spring/ea-context-security.xml
                   /WEB-INF/spring/ea-context-db.xml
        </param-value>
    </context-param>
    <context-param>
        <description>Vaadin production mode</description>
        <param-name>productionMode</param-name>
        <param-value>true</param-value>
    </context-param>
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>net.sf.ehcache.constructs.web.ShutdownListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>securityDispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>securityDispatcher</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    
    <servlet>
        <servlet-name>LoginJSP</servlet-name>
        <jsp-file>/login.jsp</jsp-file>
    </servlet>
    <servlet-mapping>
        <servlet-name>LoginJSP</servlet-name>
        <url-pattern>/login.jsp</url-pattern>
    </servlet-mapping>
    <servlet>
        <servlet-name>VaadinServlet</servlet-name>
        <servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
        <init-param>
            <param-name>UI</param-name>
            <param-value>com.explorelearning.experiments.gui.ExperimentsUI</param-value>
        </init-param>
        <init-param>
            <param-name>widgetset</param-name>
            <param-value>com.explorelearning.experiments.gui.widgetset.ReflexexperimentsWidgetset</param-value>
        </init-param>
    </servlet>

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

    <filter>
        <filter-name>characterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <welcome-file-list>
        <welcome-file>home.do</welcome-file>
    </welcome-file-list>
...

After I posted above, I closed my browser and relaunched. I got the redirect loop again on the login.jsp. Maybe there is a race condition.

Does anyone have any advice for me? Thank you.