Share / Save this...

Share/Bookmark

2010-06-26

GWT + Struts 1.x + Netbeans Tutorial (Part 4)




<c:choose>
     <c:when test="${user.likes}"
          Share this with your friends
     </c:when>
     <c:otherwise>  
          Send me feedback.
     </c:otherwise>
<:choose>
oDesk Certified Java Developer

Part 4: Create a simple Struts 1.x application.

TL;DR: Scroll down to the video.

This is a straightforward task. Simply open Netbeans, if it's not already opened, click "File" and then select "New Project" or alternatively you could Click on the "New Project" icon on the toolbar. After selecting "New Project", choose the "Java Web" category and then the "Web Application" project type. In the "New Web Application" wizard fill-in the information, such as the project name and click "next". 

I am using Google App Engine (GAE) as a web server but you can choose any servlet container you like, such as Apache Tomcat or Sun Glassfish, which come bundled with Netbeans. If you're using GAE as the server, and you haven't added it to your services (i.e. it's not selectable in the drop-down menu), click the "Add" button. Select "Google App Engine" from the server selection list and click "next". In the location, point to the easy-to-find location where you saved and unpacked the GAE SDK. Configure the properties and click "finish". Now you can use the GAE development server to develop web applications for the Google App Engine cloud server.

After selecting the server for your new web application, click "next" and head to the frameworks section and check the "Struts" framework, don't worry if your application will have i18n support because we will deal with those specific details in the following parts of the tutorial, now check the "Add Struts TLDs" check-box and click "finish". If you noticed we didn't add GWT support to the web application, although it was available from the frameworks menu. This was done intentionally to create the Struts file structure first and to configure it the way you would normally do when starting a new web application using Struts. We'll worry about GWT later, because what we just did also allows you to follow the next parts of the tutorial and apply GWT support to an existing Struts 1.x web application without having to rewrite or manually create the required file structure.


The music clips are here on the left, just in case you feel like listening to something while you read.

GAE quirks

So, we now have a new web application project with Struts support that should work in GAE (or maybe not). Except that sessions are not ON by default, so we need to modify appengine-web-xml to enable sessions using the Netbeans editor by clicking the "Enable Support for Servlet Sessions" check-box or by adding this <sessions-enabled>true</sessions-enabled> inside the root. What next? Ok, we need to adjust a few things according to the "Will it play in App Engine" page. In that page it says: 

JSP session beans are not supported; to enable EL parsing, add <% @page isElIgnored="false" %> to your JSPs and <%@tag isElIgnored="false" %> to your tag files.

So, how do we make session beans available to JSPs? We need to make them available through memcache using the persistence provided by GAE (they need to make a buck somewhere around here). I found this technique running around in the wilderness of the interwebs, but i think the low-level API gives you more control, the choice is up to you. So for now we're covered and we can pretend we can use session beans in JSP, provided we only store Serializable objects in which all the important attributes are Serializable as well.

Now we adress the other issue; EL parsing. In every page we create we need to insert the <%@page isELIgnored="false"%> directive to be able to use EL (expression language) inside our JSPs. Problem solved. 


If you have any suggestions, ideas for full blown system integration (sb) or comments, leave a message below.

I would appreciate if you could Share this with your friends



No comments:

Post a Comment

Hits