xiaoxing tech

October 31, 2008

start the HSQLDB server

Filed under: database — xiaoxing @ 1:15 pm

1. To start the HSQLDB server, open up a command line, change into your WORKDIR(C:\jee_workplace\test), and run the command: java -classpath lib/hsqldb.jar org.hsqldb.Server
2. gui tool: java -cp lib/hsqldb.jar org.hsqldb.util.DatabaseManager        Type: HSQL Database Engine Server    jdbc:hsqldb:hsql://localhost (from democal.properties)    sa    ??    )
3. (You?ll also find some new files in your WORKDIR, starting with test?these are the files used by HSQLDB to store your data. If you want to start with a fresh database, delete the files between restarts of the server.)
4. Exporting the database schema (automatic generation): (prerequisites: domain model classes and mapping-metadata-in-XML or Annotations-in-Java)    using an ant task: taskdef name=”hibernatetool” and target name=”schemaexport”.
5. database browser: ant task: target name=”dbmanager”

October 17, 2008

DWR(direct-web-remoting) starts here……

Filed under: JSP, Java, Spring, dwr — xiaoxing @ 10:11 am

dwr, java, jsp, spring

1. Download the dwr.jar (also need commons-logging)
2. Add “<servlet>” and “<servlet-mapping>” into web.xml
3. Create a dwr.xml file. This file defines what classes DWR can create and remote for use by Javascript.
4. Testing url: http://localhost:8080/[YOUR-WEBAPP]/dwr/
-----------------------------------------------------------
OK. Environment is setup. Do a simple example:
1. Inside my “hello.jsp” file’s header, insert
<script type=”text/javascript” src=”javascript/validator.js”></script>
<script type=”text/javascript” src=”/springapp/dwr/interface/DemoPercIncre.js”> </script>
<script type=”text/javascript” src=”/springapp/dwr/interface/PercentageIncre.js”> </script>
<script type=”text/javascript” src=’/springapp/dwr/engine.js’></script>
<script type=”text/javascript” src=’/springapp/dwr/util.js’></script>
<SCRIPT LANGUAGE=”JavaScript”>
function update() {
      var percent = dwr.util.getValue(“percToIncre”);
      PercentageIncre.increPrice(percent, function(data) {
        dwr.util.setValue(“IncreProcessed”, data);
      });
    }
</SCRIPT>

2. Inside “Body”, create input box:
<p>Increase Price by Percent:
<input type=”text” id=”percToIncre” onChange=”digitvalidation(this, 1, 2,’You MUST enter 1 or 2 Integer Digits’,'Integer’);” />
<input value=”Excute” type=”button” onclick=”update()” />
<br />Response: <span id=”IncreProcessed“></span>
</p>

3. Create dwr.xml under WEB-INF, to link the javascript and the java-class.
<dwr>
    <allow>
        <create creator=”new” javascript=”PercentageIncre“>
            <param name=”class” value=”springapp.web.PercentageIncre” />
        </create>
    </allow>
</dwr>

4. Then create the java-class: PercentageIncre.java
package springapp.web;
public class PercentageIncre {
    public String increPrice(String perc) {
        return “Hello, I pretend to increase the price by ” + perc + “% percent.”;
    }
}

note: WEB-INF seems to be a special folder, my hello.jsp can’t find any js files fall into that folder by using “src=…”. I have to create a “javascript” folder parallel with WEB-INF, put js files in it, and in hello.jsp use “<script type=”text/javascript” src=”javascript/validator.js”></script>” to include that validator.js file.

 

October 16, 2008

Spring…… with database (hsqldb)

Filed under: Java, Spring — xiaoxing @ 9:17 am

1. Create server.bat which contains:

java -classpath ..\war\WEB-INF\lib\hsqldb.jar org.hsqldb.Server -database test

2. Use Ant to do some targets: “ant createTables loadData printData“, sql files are stored in a folder.
3. Create JdbcProductDao.java (extends SimpleJdbcDaoSupport implements ProductDao), which includes: public List<Product> getProductList() and public void saveProduct(Product prod).
4. Modify “SimpleProductManager.java” to use “ProductDao“.
5. Modify “springapp-servlet.xml“, hard-coded product list is removed.
6. Create a new ‘applicationContext.xml’, to separate the service and persistence layer configuration from the web layer configuration.

October 15, 2008

Spring Framework starts here…

Filed under: Java, Spring — xiaoxing @ 2:50 pm

1. A basic Spring App works this way:
When we enter http://localhost:8080/springapp/  in a browser,
it should pull up the welcome file ‘index.jsp’, which should redirect
to ‘hello.htm’ and is handled by the DispatcherServlet, which in turn
delegates our request to the page controller(by springapp-servlet.xml to InventoryController.java)
that puts the date and time in the model and then makes the model available to the view ‘hello.jsp’.
—————————————-
The location of the view jsp is defined by a viewResolver, inside the page-controller xml.
so in the page-controller class, you don’t have to use the full path, just provide a logic name.

2. A form added into this app. User inputs a number, app calculates then return:
- Several beans are defined in “springapp-servlet.xml“:
      productManager (with product list)
      messageSource (ResourceBundleMessageSource)
      /hello.htm (InventoryController)
      /priceincrease.htm (PriceIncreaseFormController)
- /priceincrease.htm bean is like:
    <bean name=”/priceincrease.htm” class=”springapp.web.PriceIncreaseFormController”>
        <property name=”sessionForm” value=”true” />
        <property name=”commandName” value=”priceIncrease” />
        <property name=”commandClass” value=”springapp.service.PriceIncrease” />
        <property name=”validator”>
            <bean class=”springapp.service.PriceIncreaseValidator” />
        </property>
        <property name=”formView” value=”priceincrease” />
        <property name=”successView” value=”hello.htm” />
        <property name=”productManager” ref=”productManager” />
    </bean>

- And inside InventoryController, a reference to a ProductManager is added,
  so this time when user visits “hello.htm”, we could retrieve a list of products to display.
- User uses this link “priceincrease.htm” to the form (form in priceincrease.jsp)
- A Java bean (commandClass) “PriceIncrease.java” is created to hold the increase value.
- A SimpleFormController: PriceIncreaseFormController, do calculations, return ModelAndView.

October 14, 2008

Can not find test class ‘*****.java’ in project ‘

Filed under: JSP, Java, Spring, tomcat — xiaoxing @ 3:51 pm

I am following the Spring Framework tutorial here: http://static.springframework.org/docs/Spring-MVC-step-by-step/
While doing “1.9. Write a test for the Controller“, I ran into this error: Can not find test class ‘*****.java’ in project ‘
And, it seemed that a jar is missing: import javax.servlet.*** not successful
I suspect servlet-api.jar is missing.

My appserver.lib is ${appserver.home}/server/lib (defined in build.properties),
and in build.xml, it says:         <fileset dir=”${appserver.lib}”>             <include name=”servlet*.jar” />         </fileset>
while in appserver.lib, there is no file called: servlet-api.jar
I copied THE file from ${appserver.home}\common\lib to ${appserver.home}/server/lib,
problem solved.

A more elegant way (instead of putting the same file in two folders) of resolving this issue should exist.
Anyone gives me a hint?

October 10, 2008

Bedework setup, deploy notes & log

Filed under: JSP, Java, database — xiaoxing @ 9:21 am

Running the quickStart:
1. open cmd and go: cd C:\java_3rd_party\bedework\quickstart-3.4.1.1
2. ant.bat
3. open database: ant hsqldb    (use gui tool: cd C:\java_3rd_party\bedework\quickstart-3.4.1.1\hsqldb-1.7.3.3\lib    java -cp hsqldb.jar org.hsqldb.util.DatabaseManager    Type: HSQL Database Engine Server    jdbc:hsqldb:hsql://localhost:8887 (from democal.properties)    sa    “”    try SELECT * FROM bw_calendars)
4. open a new cmd window, go: cd C:\java_3rd_party\bedework\quickstart-3.4.1.1 and do: ant tomcatstart; wait to see ([java] INFO: Server startup in 22455 ms)
5. open http://localhost:8080/bedework/

Own Deployment:
1. (optional) setting bedework.build.properties under folder: C:\Documents and Settings\xxzhao; if not setting, system will use: democal.properties and democal.options.xml under folder: C:\netbeansWork\my_quickstart-3.4.1.1\bedework\config\configs
2. democal.properties: for deployment use. To decide: which app to install? etc…
3. democal.options.xml: for use in runtime. e.g.    <name>bedework</name>    <tzid>America/New_York</tzid>    <systemid>demobedework@cal.mysite.edu</systemid>
4. stylesheets and associated template images and resources: ?app.<name>.root?, ?app.<name>.cal.suite?    in the config file (e.g. C:\netbeansWork\my_quickstart-3.4.1.1\bedework\config\configs\myconfig.properties).
5. modify “personal web client” app(webapps): org.bedework.app.UserCal.tomcat.context.xml=war/META-INF/usercontext.xml;    C:\netbeansWork\my_quickstart-3.4.1.1\bedework\projects\webapps\webclient\war\META-INF    C:\netbeansWork\my_quickstart-3.4.1.1\bedework\build: for hibernate dialect
6. create a schema: The deploy process created a zip file in the C:\netbeansWork\my_quickstart-3.4.1.1\bedework\dist directory, which can be unwrapped to run the schema build.    Run bwrun schema: produces a file ?schema.sql?.    Then do: bwrun schema-export: to create all the tables and constraints
7. initialize the database: bwrun initdb -ndebug -indexroot path-for-lucene
8. To dump the database data use    bwrun dump <filename>                To restore the data use: bwrun restore <filename> -ndebug -indexroot path-for-lucene
9. __newThread__: use this res file: C:\netbeansWork\my_quickstart-3.4.1.1\bedework\dist\dumpres.zip        extract it to: C:\netbeansWork\my_quickstart-3.4.1.1\xxz\dumpres
10. stop hsqldb, rename hsqldb-1.7.3.3/demo folder.
11. Restart HSQL, and Hypersonic will create a new, empty demo database: cd C:\netbeansWork\my_quickstart-3.4.1.1\    ant.bat    ant hsqldb    (use gui tool: cd C:\netbeansWork\my_quickstart-3.4.1.1\hsqldb-1.7.3.3\lib    java -cp hsqldb.jar org.hsqldb.util.DatabaseManager    Type: HSQL Database Engine Server    url: jdbc:hsqldb:hsql://localhost:8887 (from democal.properties)    sa    “”    try SELECT * FROM bw_calendars)        as you see, the database is empty, and a new “hsqldb-1.7.3.3/demo” folder is created.
12. to insert data, under dumpres folder: bwrun.bat schema-export        so the structure is established, yet no data.
13. Finally, initialize the database with dumpres/data/initbedework.xml: bwrun.bat initdb    this takes some time…… Elapsed time: 0:19    (full version: bwrun.bat initdb -ndebug -indexroot path-for-lucene)
14. build: in cd C:\netbeansWork\my_quickstart-3.4.1.1: ant clean.deploy.debug    (takes some time: Total time: 2 minutes 53 seconds)    (or doing it without debug: ant clean.deploy)    This will create a number of WAR files in <bedwork>/dist/ including for example: cal.war, caladmin.war, and ucal.war                in C:\netbeansWork\my_quickstart-3.4.1.1 do: ant tomcatstart (INFO: Server startup in 35950 ms)    now it’s deployed: goto: http://localhost:8080/bedework
15. continue from here: 30 of 49 of the manual

October 6, 2008

solution: The value for the useBean class xxxx.Xxxxx is invalid.

Filed under: JSP — xiaoxing @ 11:14 am

I am trying to output something from a “jsp:getProperty” by using following code inside a JSP page:

        <jsp:useBean id=”sche” class=”bean.scheduleBean” scope=”request” >
            <jsp:setProperty name=”sche” property=”testing” value=”y”/>
            <jsp:getProperty name=”sche” property=”testing”/>
        </jsp:useBean>

And I got following error message:
org.apache.jasper.JasperException: /Catalog/itemsview.jsp(2,0) The value for the useBean class attribute bean.scheduleBean is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:357)

……

Reason: when doing “<jsp:useBean id=”sche” class=”bean.scheduleBean” scope=”request” >”, Java needs the bean class having a no-argument constructor, which my scheduleBean didn’t have. So I added following code to the bean class, and solved problem:

    public scheduleBean() {
    }

October 2, 2008

JoSQL error: java.lang.NoClassDefFoundError: com/gentlyweb/utils/Getter at

Filed under: Java — xiaoxing @ 9:11 am

The problem is: I didn’t set the JoSQL Library correctly.
In NetBeans, put both jar files of JoSQL under “Library Classpath”:
…… JoSQL-2.0.jar
…… gentlyWEB-utils-1.1.jar

ps. Put the folder of “gentlyWEB-utils-1.1.jar” into “Library Classpath” is the wrong way!

Blog at WordPress.com.