Changeset 1125


Ignore:
Timestamp:
Jun 15, 2009, 12:31:14 PM (12 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #233: Add example that uses the alternate approach for invoking servlets

Location:
extensions/net.sf.basedb.examples/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.examples/trunk/META-INF/extensions.xml

    r1094 r1125  
    173173        <title>Hello Servlet world!</title>
    174174        <tooltip>Opens a Servlet generated page with the message</tooltip>
    175         <onClick>Main.openPopup('$HOME$/HelloWorld.servlet?ID=' + getSessionId(), 'HelloServletWorld', 400, 300)</onClick>
     175        <onClick>Main.openPopup('$HOME$/HelloWorld/with/some/path-info.servlet?ID=' + getSessionId(), 'HelloServletWorld', 400, 300)</onClick>
    176176        <icon>~/images/servlet.png</icon>
    177177      </parameters>
    178178    </action-factory>
    179179  </extension>
    180 
     180  <extension
     181    id="menu.helloservletworld2"
     182    extends="net.sf.basedb.clients.web.menu.extensions"
     183    >
     184    <index>7</index>
     185    <about>
     186      <name>Hello Servlet world (alternate)</name>
     187      <description>
     188        This example uses a custom Servlet page to display the
     189        "Hello world" message instead of a javascript popup.
     190        The difference from the above menu is that this uses an
     191        alternate path to the servlet.
     192      </description>
     193    </about>
     194    <action-factory>
     195      <factory-class>
     196        net.sf.basedb.clients.web.extensions.menu.FixedMenuItemFactory
     197      </factory-class>
     198      <parameters>
     199        <menuId>hello</menuId>
     200        <title>Hello Servlet world (alternate)!</title>
     201        <tooltip>Opens a Servlet generated page with the message</tooltip>
     202        <onClick>Main.openPopup('$SERVLET_HOME$/HelloWorld/with/other/path?ID=' + getSessionId(), 'HelloServletWorld', 400, 300)</onClick>
     203        <icon>~/images/servlet.png</icon>
     204      </parameters>
     205    </action-factory>
     206  </extension>
    181207  <extension
    182208    id="toolbar.iteminfo"
  • extensions/net.sf.basedb.examples/trunk/META-INF/servlets.xml

    r1019 r1125  
    66    <init-param>
    77      <param-name>template</param-name>
    8       <param-value>Hello {user}! Welcome to the Servlet world!</param-value>
     8      <param-value><![CDATA[
     9            <h2>Hello {user}! Welcome to the Servlet world!</h2>
     10            <b>URL:</b> {url}<br>
     11            <b>Servlet-path:</b> {servlet-path}<br>
     12            <b>Path-info:</b> {path-info}<br>
     13            <b>Query string:</b> {query}<br>
     14          ]]>
     15      </param-value>
    916    </init-param>
    1017  </servlet>
  • extensions/net.sf.basedb.examples/trunk/src/net/sf/basedb/examples/extensions/servlet/HelloWorldServlet.java

    r1019 r1125  
    1414import net.sf.basedb.core.SessionControl;
    1515import net.sf.basedb.core.User;
     16import net.sf.basedb.util.Values;
    1617
    1718/**
     
    5253      User current = User.getById(dc, sc.getLoggedInUserId());
    5354      PrintWriter out = response.getWriter();
    54       out.print(template.replace("{user}", current.getName()));
     55      response.setContentType("text/html");
     56      String html = template;
     57      html = html.replace("{user}", current.getName());
     58      html = html.replace("{url}", request.getRequestURL());
     59      html = html.replace("{servlet-path}", Values.getString(request.getServletPath(), "null"));
     60      html = html.replace("{path-info}", Values.getString(request.getPathInfo(), "null"));
     61      html = html.replace("{query}", Values.getString(request.getQueryString(), "null"));
     62      out.print(html);
     63     
    5564    }
    5665    finally
Note: See TracChangeset for help on using the changeset viewer.