java groovy
Solution:
My system’s CLASSPATH variable contains this entry: C:\midp2.0fcs\classes
Delete it then groovyConsole.bat will work.
Other entries in the CLASSPATH don’t matter.
java groovy
Solution:
My system’s CLASSPATH variable contains this entry: C:\midp2.0fcs\classes
Delete it then groovyConsole.bat will work.
Other entries in the CLASSPATH don’t matter.
email, java, server, app
1. Install Mail Server Pro (one month trial). A windows service (SMTP Server Service) will be installed.
Change settings: Authentication is not required.
IP Range Lists, add “1×2.1x.6.x9″ local ip address.
Local Domains add chao.com
Domain Users add “richie” and “xing”
2. Outlook add account: richie@zhao.com; POP3 incoming server “1×2.1x.6.x9″; SMTP localhost; user name “richie@zhao.com”
3. In java code (-context.xml): sender (JavaMailSenderImpl)’s host property: localhost
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.
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
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
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.
regex java
US Zip Code: \d{5}(?:-\d{4})?
A zip code has two formats: five digits OR five digits, a hyphen and four more digits.
\d{5}: the pattern starts with five digits. The 5 within the braces indicates that the previous pattern should match five times.
(?:-\d{4})?: It’s a non-capturing parenthesis, starts with (?:. Question mark at the end means optional.
-\d{4}: a hyphen followed by four digits
US SSN(social security number): \d{3}([-]?)\d{2}\1\d{4}
the digits are written in two different ways: as nine digits or as three digits, a hyphen, two digits, another hyphen and four more digits.
\d{3}: The pattern starts with three digits
([-]?): is a capturing group. Inside the group is an optional hyphen. Whatever matches inside the parentheses will be remembered and can be recalled later in the pattern as \1.
\d{2}: two more digits.
\1: the symbol for the grouped pattern from earlier in the regular expression. If a hyphen was used earlier in the expression, then a hyphen must be used here. If a hyphen was not matched earlier, then a hyphen cannot be entered here.
\d{4}: four more digits.
User ID: [a-zA-Z]{3,5}[a-zA-Z0-9]?\d{2}
might be from three to five letters followed by three digits or three to six letters followed by two digits.
Note: When writing regular expressions in Java, each \ character must be written as double backslashes, \\.
1. Square brackets define a character class. [xyz] will match x, y or z, but only one of them.
2. If the class starts with ^, then it will match all characters that are not listed inside the brackets: [^abc] any character except a, b or c (negation)
3. A hyphen can be used to include a range of characters: [a-z] will match any lowercase letter. [a-zA-Z] a through z or A through Z, inclusive (range)
| Character Class | Meaning |
|---|---|
| . | Any character, except line terminators |
| \d | A digit: [0-9] |
| \D | A non-digit: [^0-9] |
| \s | A whitespace character: [ \t\n\x0B\f\r] |
| \S | A non-whitespace character: [^\s] |
| \w | A word character: [a-zA-Z_0-9] |
| \W | A non-word character: [^\w] |
google, java
(libraries needed: gdata, JavaMail, servlet2.4)
In Eclipse, under application’s context menu “run as, run configurations”:
program arguments: xxzhao@gmail.com xxzhaospsw
VM arguments: -Dhttp.proxyHost=proxysrv007-zhengxian -Dhttp.proxyPort=8080 -Dhttps.proxyHost=proxysrv007-zhengxian -Dhttps.proxyPort=8080 -Dhttp.proxyUser=liezi.info\xxing -Dhttp.proxyPassword=e*********
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.
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.