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.
November 21, 2008
Failed to load or instantiate TagLibraryValidator class
November 19, 2008
hibernate-validator-3.1.0.GA not compatible with Core_hibernate-distribution-3.3.1.GA
Use hibernate-validator-3.1.0.GA with Core_hibernate-distribution-3.3.1.GA,
got this error:
java.lang.NoSuchMethodError: org.hibernate.event.PreUpdateEvent.getSource()Lorg/hibernate/engine/SessionImplementor;
at org.hibernate.validator.event.ValidateEventListener.onPreUpdate(ValidateEventListener.java:177)
at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:237)
solution: download hibernate-distribution-3.3.0.SP1, use the old hibernate3.jar to replace the new one in distribution-3.3.1.GA.
http://opensource.atlassian.com/projects/hibernate/browse/HV-66
java.lang.NoSuchFieldError: name org.slf4j.impl.Log4jLoggerAdapter.(Log4jLoggerAdapter.java
problem: AnnotationConfiguration cfg = new AnnotationConfiguration(); fails
and javax.servlet.ServletException: Servlet.init() for servlet PersistentController threw exception
java.lang.NoSuchFieldError: name
org.slf4j.impl.Log4jLoggerAdapter.<init>(Log4jLoggerAdapter.java:75)
solution: download a new http://www.slf4j.org/dist/slf4j-1.5.2.tar.gz
(having multiple javassist.jar doesn’t matter)
http://groups.google.com/group/comp.lang.java.programmer/browse_thread/thread/c6d647699b02fb5e/becc5c738902506b?tvc=2#becc5c738902506b
November 17, 2008
servlet problem: hibernate-validator (requestValidator.getInvalidValues(data) fails)
This section of code fails (data is the bean object):
InvalidValue[] validationMessages;
ClassValidator requestValidator = new ClassValidator(data.getClass());
validationMessages = requestValidator.getInvalidValues(data); //fails here!
Don’t know why but this works (“hobby” is one of the fields of the data bean):
requestValidator.getInvalidValues(data, “hobby”)
So, I modified the whole section to use request’s getParameterMap to traverse each bean property:
InvalidValue[] validationMessages;
List<InvalidValue[]> validationMsgList = new ArrayList<InvalidValue[]>();
ClassValidator requestValidator = new ClassValidator(data.getClass());
Map pMap = request.getParameterMap();
Iterator ParIt = pMap.entrySet().iterator();
while (ParIt.hasNext()) {
Map.Entry pairs = (Map.Entry) ParIt.next();
String key = “” + pairs.getKey();
validationMessages = requestValidator.getInvalidValues(data, key);
validationMsgList.add(validationMessages);
}
App finally runs.
October 17, 2008
DWR(direct-web-remoting) starts here……
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 14, 2008
Can not find test class ‘*****.java’ in project ‘
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
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.
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() {
}
August 13, 2007
July 25, 2007
JSP day 3, writing code
1. The character sequences <%= and %> enclose Java expressions, which are evaluated at run time.
Write this in jsp file: <%= new java.util.Date() %>
You’ll get current time.
Only good for simple java code.
2. You do Scriptlets by placing your larger Java code between <% and %> characters (just like expressions, but without the = sign at the start of the sequence.)
<HTML><BODY><% // This is a scriptlet. Notice that the "date" // variable we declare here is available in the // embedded expression later on. System.out.println( "Evaluating date now" ); java.util.Date date = new java.util.Date();%>Hello! The time is now <%= date %></BODY></HTML> Notice the output from the "System.out.println" will be on the server log.
3. Using “out” variable in Scriptlet, to generate HTML.
<HTML><BODY><% // This scriptlet declares and initializes "date" System.out.println( "Evaluating date now" ); java.util.Date date = new java.util.Date();%>Hello! The time is now<% // This scriptlet generates HTML output out.println( String.valueOf( date ));%></BODY></HTML> The "out" variable is of type javax.servlet.jsp.JspWriter.
4. Using “request” variable of type javax.servlet.http.HttpServletRequest
<HTML><BODY><% // This scriptlet declares and initializes "date" System.out.println( "Evaluating date now" ); java.util.Date date = new java.util.Date();%>Hello! The time is now<% out.println( date ); out.println( "<BR>Your machine's address is " ); out.println( request.getRemoteHost());%></BODY></HTML>
Note: request variable is sent by client, processed by server, and return the result of the method to client.
5. Generate a dynamic table, by mixing HTML, Scriptlet and Java-Expression
<HTML><BODY> <% int n = 120; %> <TABLE BORDER=1> <% for ( int i = 0; i < n; i++ ) { %> <TR> <TD>Number</TD> <TD><%= i+1 %></TD> </TR> <% } %> </TABLE></BODY></HTML>
Note: declare a variable n =120, the <TR> … </TR> will run 120 times. With two columns.
Just another example:
<% boolean hello = false; %>
<%
if ( hello ) {
%>
<P>Hello, world
<%
} else {
%>
<P>Goodbye, world
<%
}
%>
To get system’s properties:
<%=System.getProperties().toString() %>
6. import (a directive)
<%@ page import="java.util.*" %><HTML><BODY><% System.out.println( "Evaluating date now" ); Date date = new Date();%>Hello! The time is now <%= date %></BODY></HTML>
Note: The first line in the above example is called a “directive“. A JSP “directive” starts with <%@ characters.
This one is a “page directive“.
To import more than one item:
<%@ page import="java.util.*,java.text.*" %>
7. include directive
<HTML><BODY>Going to include hello.jsp...<BR><%@ include file="hello.jsp" %></BODY></HTML>
8. Tag (jsp tags and non-jsp tags)
jsp:include
usage
<HTML><BODY>Going to include hello.jsp...<BR><jsp:include page="hello.jsp"/></BODY></HTML>
Note: another way of doing include. Tags have XML style.
do forward:
<jsp:forward page=”zxx.html”/>
8. use session
in first page, use a “Form” and a “Text Input” to accept user’s input
<FORM METHOD=POST ACTION=”SaveName.jsp”>
What’s your name? <INPUT TYPE=TEXT NAME=username SIZE=20>
<P><INPUT TYPE=SUBMIT>
</FORM>
in second page, save the “name” to a variable.
<%
String name = request.getParameter( “username” );
session.setAttribute( “theName”, name );
%>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
<title>JSP Page</title>
</head>
<body>
<h1>JSP Page</h1>
<A HREF=”NextPage.jsp”>Continue</A>
</body>
</html>
then in the third page, user can still retrieve the value
<%= session.getAttribute( “theName” ) %>
9. use bean to correspond HTML form.
i. design a HTML form
<HTML><BODY><FORM METHOD=POST ACTION="SaveName.jsp">What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20><BR>What's your e-mail address? <INPUT TYPE=TEXT NAME=email SIZE=20><BR>What's your age? <INPUT TYPE=TEXT NAME=age SIZE=4><P><INPUT TYPE=SUBMIT></FORM></BODY></HTML> ii. define a Java class with fields "username", "email" and "age"class: UserData package: me iii. use this class in the file "SaveName.jsp"<jsp:useBean id="user" class="me.UserData" scope="session"/><jsp:setProperty name="user" property="*"/>
These two lines of code will handle all the properties.
It will save the user’s data in the bean instance.
iv. in “NextPage.jsp“, retrieve the properties
<jsp:useBean id=”user” class=”me.UserData” scope=”session”/>
in <body>, use <%= user.getUsername() %>
Powered by ScribeFire.