xiaoxing tech

November 21, 2008

Failed to load or instantiate TagLibraryValidator class

Filed under: JSP, Java, Spring — xiaoxing @ 9:52 am

running the springMVC-petclinic-hibernate sample app,
got this:
SEVERE: Exception Processing ErrorPage[exceptionType=java.lang.Exception, location=/WEB-INF/jsp/uncaughtException.jsp]
org.apache.jasper.JasperException: /WEB-INF/jsp/uncaughtException.jsp(1,1) Failed to load or instantiate TagLibraryValidator class: org.apache.taglibs.standard.tlv.JstlCoreTLV
        at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)

solution: create a folder springMVC-petclinic-hibernate\web\WEB-INF\lib, then put jstl.jar and standard.jar inside it.
reason: even though the jstl.jar is already in classpath, it’s ignored by the servlet container; have to put the jar along with jsp pages manually.

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?

Blog at WordPress.com.