转眼从十一到现在没来过了,一直加班 加班 加班
2011年12月27日星期二
2011年9月23日星期五
How-to-bind-String-to-java.sql.Timestamp
http://forum.springsource.org/showthread.php?48979-How-to-bind-String-to-java.sql.Timestamp
java.sql.TimeStamp is derived from java.util.Date. It shouldn't be hard to figure out how to handle that in the persistence layer- in fact I'm willing to bet that some persistence tools can handle that conversion automatically.
In regard to your command object, however, you have a tougher problem using TimeStamp. I'll explain why.
As I noted, TimeStamp is derived from java.util.Date. Spring has an out-of-the-box CustomDateEditor property editor that does conversions from Strings (like on a form filled out by a user) to java.util.Date. It also converts from java.util.Date back to String when a BindingResult is being used to re-populate form fields because the submission failed validation.
Now, for the CustomDateEditor to take the Date it has converted your String to and "jam" it into a TimeStamp field is not possible because it requires an explicit downcast. Spring does no such thing on your behalf. In fact- off the top of my head, I don't think such a downcast is even legal in Java- meaning you'd get an exception.
Do you see why I'm recommending going back to java.util.Date? It's the standard class used for transporting date (and time) information.
If you're really gung-ho about sticking with java.sql.TimeStamp, however, your next best bet is to create your own CustomTimeStampEditor. Basically crack open and copy the code for Spring's CustomeDateEditor and then modify it to suit TimeStamp.
2011年9月20日星期二
jquery定义除输入框之外的背景色
$j("table.infoTable tr td").each(function(){var child = $j(this).children().eq(0);if(!child.is("input") && !child.is("select") && !child.is("textarea")&& !child.is("span")) $j(this).css('backgroundColor', '#e6eff3'); });
2011年9月13日星期二
2011年9月5日星期一
Spring事务管理与异常处理注意事项
任何RuntimeException 将触发事务回滚,但是任何checked Exception 将不触发事务回滚
在dao 、servcie层都不要try catch,即使try catch 也要在catch中throw ServiceException供controler捕获
在controler中处理异常,所有catch都要ServiceException(自定义异常类 继承于RuntimeException)
参考:http://www.iteye.com/topic/34867
http://www.4ucode.com/Study/Topic/649831
@InitBinder 日期转换
@Controller
public class AbstractController {
private String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@InitBinder
protected void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(Integer.class, null,
new CustomNumberEditor(Integer.class, null, true));
binder.registerCustomEditor(Long.class, null,
new CustomNumberEditor(Long.class, null, true));
binder.registerCustomEditor(byte[].class,
new ByteArrayMultipartFileEditor());
binder.registerCustomEditor(Date.class,new PropertyEditorSupport() {
public void setAsText(String value) {
try {
setValue(new SimpleDateFormat(Constants.DATE_FORMAT).parse(value));
} catch(ParseException e) {
setValue(null);
}
}
public String getAsText() {
return new SimpleDateFormat(Constants.DATE_FORMAT).format((Date) getValue());
}
});
}
}
自定义异常处理类
packagecom.capinfo.webapp.handler;
importorg.apache.commons.logging.Log;
importorg.apache.commons.logging.LogFactory;
importorg.springframework.web.servlet.HandlerExceptionResolver;
importorg.springframework.web.servlet.ModelAndView;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
importjava.util.HashMap;
importjava.util.Map;
/**
* Created by IntelliJ IDEA.
* User: liuzhaochun
* Date: 11-8-12
* Time: 下午5:18
* 自定义异常处理类.
*/
public classMyHandlerExceptionResolver implements HandlerExceptionResolver {
private Log log =LogFactory.getLog(getClass());
public ModelAndViewresolveException(HttpServletRequest request,
HttpServletResponse httpServletResponse,
Object o, Exception ex) {
log.warn("Handle exception: "+ ex.getClass().getName());
Map model = newHashMap();
model.put("ex",ex.getClass().getSimpleName());
model.put("error",ex.getMessage());
return newModelAndView("error", model);
}
}
Jsp:error.jsp
<%@page language="java" pageEncoding="UTF-8"contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<%@ includefile="/include/meta.jsp"%>
</head>
<bodyid="error">
<div id="page">
<div id="content"class="clearfix">
<div id="main">
<h1>哦!</h1>
${ex}</br>
${error}
</div>
</div>
</div>
</body>
</html>
url-pattern问题
spring用到forward("/WEB-INF/jsp/*.jsp")
而forward当然是又要经过web.xml的映射的,
然后,在URL匹配时,
<url-pattern> / </url-pattern> 不会匹配到*.jsp,不会进入spring的DispatcherServlet类
<url-pattern> /* </url-pattern> 会匹配*.jsp,导致进入spring的DispatcherServlet 类,然后去寻找controller,接着找不到对应的controller所以报错。
总之,关于web.xml的url映射的小知识:
<url-pattern>/</url-pattern> 会匹配到/login这样的路径型url,不会匹配到模式为*.jsp这样的后缀型url
<url-pattern>/*</url-pattern> 会匹配所有url:路径型的和后缀型的url(包括/login,*.jsp,*.js和*.html等)
SpringMVC 配置2
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"
default-lazy-init="true">
<!-- 配置静态资源,直接映射到对应的文件夹,不被DispatcherServlet处理,3.04新增功能,需要重新设置spring-mvc-3.0.xsd -->
<mvc:resources mapping="/images/**" location="/images/"/>
<mvc:resources mapping="/js/**" location="/js/"/>
<mvc:resources mapping="/css/**" location="/css/"/>
<mvc:resources mapping="/include/**" location="/include/"/>
<mvc:default-servlet-handler/>
<!-- 自定义异常处理类-->
<bean id="exceptionResolver" class="com.capinfo.webapp.handler.MyHandlerExceptionResolver"> </bean>
<!-- 自动搜索@Component , @Controller , @Service , @Repository等标注的类 -->
<context:component-scan base-package="com.capinfo.webapp.controller"/>
<!-- Configures the @Controller programming model -->
<!-- 支持spring mvc新的注解类型 详细spring3.0手册 15.12.1 mvc:annotation-driven-->
<mvc:annotation-driven/>
<!-- Convenient way to map URLs to JSPs w/o having a Controller
当请求/admin/activeUsers时将转发到视图/WEB-INF/pages/admin/activeUsers.jsp中
-->
<mvc:view-controller path="/mainMenu" view-name="mainMenu"/>
<mvc:view-controller path="/error" view-name="error"/>
<!-- View Resolver for JSPs -->
<!-- 对模型视图名称的解析,即在模型视图名称添加前后缀,在requestmapping输入的地址后自动调用该类进行视图解析-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<!-- 拦截器 -->
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/jd/*" />
<mvc:mapping path="/sq/*" />
<mvc:mapping path="/tcs/*" />
<mvc:mapping path="/unit/*" />
<mvc:mapping path="/mainMenu*" />
<bean class="com.capinfo.webapp.inteceptor.CheckAuthorityInteceptor"></bean>
</mvc:interceptor>
</mvc:interceptors>
</beans>
3、 applicationContext-resources.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd" default-autowire="byName">
<!-- 注意上面的default-autowire="byName",如果没有这个声明那么HibernateDaoSupport中的sessionFactory不会被注入 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>
<!-- JNDI DataSource for J2EE environments -->
<!--<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/appfuse"/>-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="maxActive" value="100"/>
<property name="maxWait" value="1000"/>
<property name="poolPreparedStatements" value="true"/>
<property name="defaultAutoCommit" value="true"/>
</bean>
</beans>
4、 applicationContext-service.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd" default-autowire="byName">
<!-- 注意上面的default-autowire="byName",如果没有这个声明那么HibernateDaoSupport中的sessionFactory不会被注入 -->
<!-- Enable @Transactional support -->
<tx:annotation-driven/>
<!-- Activates scanning of @Autowired -->
<context:annotation-config/>
<!-- 自动搜索@Component , @Controller , @Service , @Repository等标注的类 -->
<context:component-scan base-package="com.capinfo.service"/>
<!-- 定义事务规则
如果 PlatformTransactionManager bean的名字是 'transactionManager' 的话,
你的事务通知(<tx:advice/>)中的 'transaction-manager' 属性可以忽略。
否则你则需要明确指定transaction-manager="transactionManager"
-->
<tx:advice id="txAdvice">
<tx:attributes>
<!-- Read-only commented out to make things easier for end-users -->
<!-- http://issues.appfuse.org/browse/APF-556 -->
<!--tx:method name="get*" read-only="true"/-->
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<!-- =================================================================== -->
<!-- AOP: Configuration and Aspects 定义切面 并与 事务规则绑定 -->
<!-- =================================================================== -->
<aop:config>
<!-- 定义一个匹配service包下*Manager类下所有方法的切面 都执行txAdvice事务逻辑规则 -->
<aop:advisor id="managerTx" advice-ref="txAdvice" pointcut="execution(* *..service.*Manager.*(..))" order="2"/>
</aop:config>
</beans>
5、 applicationContext-dao.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd" default-autowire="byName">
<!-- 注意上面的default-autowire="byName",如果没有这个声明那么HibernateDaoSupport中的sessionFactory不会被注入 -->
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingDirectoryLocations">
<list><!-- 这里直接映射的pojo类所在的包,简单方便不用没次加一个pojo类都需要到这里来添加 -->
<value>classpath:com/capinfo/pojo</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=${hibernate.dialect}
hibernate.query.substitutions=true 'Y', false 'N'
hibernate.cache.use_second_level_cache=true
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
hibernate.hbm2ddl.auto=${hibernate.hbm2ddl.auto}
</value>
</property>
</bean>
<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- Activates scanning of @Autowired -->
<context:annotation-config/>
<!-- 自动搜索@Component , @Controller , @Service , @Repository等标注的类 -->
<context:component-scan base-package="com.capinfo.dao"/>
</beans>
SpringMVC 配置1
SpringMVC 配置
1、 web.xml
<?xmlversion="1.0" encoding="UTF-8"?>
<web-appxmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<!-- Context Configuration locations forSpring XML files -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/applicationContext-resources.xml
classpath:/applicationContext-dao.xml
classpath:/applicationContext-service.xml
</param-value>
</context-param>
<!--如果不定义webAppRootKey参数,那么webAppRootKey就是缺省的"webapp.root"。但最好设置,
以免项目之间的名称冲突。
定义以后,在Web Container启动时将把ROOT的绝对路径写到系统变量里。
然后log4j的配置文件里就可以用${webName.root }来表示Web目录的绝对路径,把log文件存放于webapp中。
此参数用于后面的“Log4jConfigListener”-->
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>webapp.root</param-value>
</context-param>
<!--Spring默认刷新Log4j配置文件的间隔,单位为millisecond-->
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>60000</param-value>
</context-param>
<!--由Sprng载入的Log4j配置文件位置-->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--Spring log4j Config loader
需要放在ContextLoaderListener之前
否则会提示log4j:WARN No appenders couldbe found for logger (org.springframework.web.context.ContextLoader)
-->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>10</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>500</error-code>
<location>/error.jsp</location>
</error-page>
<error-page>
<error-code>400</error-code>
<location>/index.jsp</location>
</error-page>
<error-page>
<error-code>403</error-code>
<location>/403.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/404.jsp</location>
</error-page>
</web-app>
2011年4月1日星期五
maven理解笔记
1、maven的生命周期 resources:resources--->compiler:compiler-->resources:testResources-->compiler:testCompile-->surefire:test-->jar:jar
2、maven的传递性依赖,在我们的项目中只需定义直接的依赖,maven会自动搜索并添加所有依赖并处理之间的冲突,在maven库中不仅有jar文件还有一个定义了依赖关系的pom文件,以实现依赖的查找。
3、依赖分为测试范围test 、编译范围compile、provided 范围(只在编译时使用,部署时已由容器提供,Servlet API 第三方开源实现Apache Geronimo org.apache.geronimo.specs)
4、配置jetty插件
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
5、maven 插件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
2011年3月31日星期四
英语不好 ... 要。。。命 啊
好久没来写写了,时常过来逛逛,想想缺没什么说的
过年回来比较闲,在捣鼓 struts2 jpbm spring hibernate maven nexus
刚刚把nexus配好了,看到maven开始从nexus私服上下载了,舒心.....
蒸腾了大半天,竟然是因为搞错ordered group Repositories和available Repositories
我把所有的库托到了available Repositories 中,然后不停的ReIndex 晕死 就是不出来 哈哈
看来莺歌里氏很瓶颈啊
2011年3月3日星期四
关于javascript闭包
function Test(){
var num = 1;
AddNum = function(){num++;};
function getNum(){
alert(num);
}
return getNum;
}
var test = Test();
test();//1
AddNum();
test();//2
用闭包貌似可以模拟java中类的概念
Test是一个类
num是一个字段
getNum是get方法
AddNum是一个方法 这里不用var声明,为的是可以在全局访问
自己的一点理解,还在深入
AddNum是一个
2011年1月10日星期一
textarea替换回车换行空格
while(jianjie.indexOf("\n")!=-1){
jianjie = jianjie.substring(0,jianjie.indexOf("\n"))+"<br>"+jianjie.substring(jianjie.indexOf("\n")+1);
}
while(jianjie.indexOf(" ")!=-1){
jianjie = jianjie.substring(0,jianjie.indexOf(" "))+" "+jianjie.substring(jianjie.indexOf(" ")+1);
}
out.println(jianjie);
weblogic中部署多个使用了hibernate的应用 SessionFactory not available
一直以来我这边的工作就是在一个已有系统上克隆成一个又一个系统,超级无聊,以至于打断点跟踪时 eclipse经常犯晕跳到另外一个系统的同package同名的类中
今天又是两个及其相似的系统部署到了weblogic上,发现一个能访问数据库一个不行,一个行了 另一个又不行
最后发现hibernate.cfg.xml中
<property name="hibernate.session_factory_name">hibernate_session</property>
两个应用中hibernate.session_factory_name值是一样的
改成不一样的值就OK了
JNDI不能重名
2010年12月3日星期五
Unable to read TLD "META-INF/c.tld" from JAR file
failed to load or instantiate taglibraryvalidator class: org.apache.taglibs.standard.tlv.jstlcoretlv
网上搜了很多,说的最多的原因是缺少standard.jar jstl.jar
但我的lib里面有这两个jar
而后发现删除javax.servlet.jar javax.servlet.jsp.jar 就不报错了
参考:http://ilinux.javaeye.com/blog/245380
另外这个错误出现在Tomcat5.5中
而在Tomcat5.0中确不报错
2010年11月15日星期一
部署到GAE时中途退出后引起的问题
如果部署GAE时正在upload files时退出,下次部署时会报错
Another transaction by user is already in progress for this app and major version. That user can undo the transaction with appcfg.py's "rollback" command
找到eclipse中的GAE SDK目录
如:D:\eclipse\plugins\com.google.appengine.eclipse.sdkbundle.1.3.8_1.3.8.v201010161055\appengine-java-sdk-1.3.8\bin
执行命令
appcfg.cmd rollback 后面跟gae项目war所在目录
如 appcfg.cmd rollback D:/spring/eclipse_workspace/taobaoke/war
执行:
********************************************************
Warning: Future versions of the Dev App Server will require Java 1.6 or later. P
lease upgrade your JRE.
********************************************************
Reading application configuration data...
2010-11-15 9:34:23 com.google.apphosting.utils.config.AppEngineWebXmlReader read
AppEngineWebXml
信息: Successfully processed D:/spring/eclipse_workspace/taobaoke/war\WEB-INF/ap
pengine-web.xml
2010-11-15 9:34:23 com.google.apphosting.utils.config.AbstractConfigXmlReader re
adConfigXml
信息: Successfully processed D:/spring/eclipse_workspace/taobaoke/war\WEB-INF/we
b.xml
2010-11-15 9:34:23 com.google.apphosting.utils.config.AbstractConfigXmlReader re
adConfigXml
信息: Successfully processed D:/spring/eclipse_workspace/taobaoke/war\WEB-INF/cr
on.xml
Beginning server interaction for taokeapp...
0% Rolling back the update.
Success.
Cleaning up temporary files...
2010年10月23日星期六
汉字按拼音排序
import java.util.Comparator;
class PinYinComparator implements Comparator<String> {
public int compare(String s1, String s2) {
return ((java.text.RuleBasedCollator)java.text.Collator.
getInstance(java.util.Locale.CHINA)).compare(s1, s2);
}
}
但是在GWT中不支持java.text...
改成这样
new Comparator<Object>() {
@Override
public int compare(Object o1, Object o2) {
return javascriptSort(o1, o2);
}
private native int javascriptSort(Object a, Object b)/*-{
return a.localeCompare(b);
}-*/;
}
2010年10月22日星期五
在GAE上简单实现了一个淘宝客
在网上无意搜到一个用Ext实现的淘宝客,恩 ,咱用GWT做一个车轮
下了淘宝的 SDK for java就开干 参考API文档按部就班
在淘宝的沙箱里测试,很顺利,乘胜前进,到正式环境下测试
问题来了
invalid signature
网上搜了一通,有说时间戳不对,果不其然,GAE使用的是标准时间,整整差了8小时,遂在获得的当前时间上加了8小时,OK
invalid signature 可能的另一个原因是APP_KEY 或 APP_SERCET不正确,仔细检查
调用 taobao.item.get
1 TaobaoClient client=new DefaultTaobaoClient(TaobaokeConstant.SANDBOX_URL, TaobaokeConstant.APP_KEY, TaobaokeConstant.APP_SERCET);
2 ItemcatsGetRequest req=new ItemcatsGetRequest();
3 java.util.Calendar c=java.util.Calendar.getInstance(TimeZone.getTimeZone("GMT+8"));
4 c.add(Calendar.HOUR, 8);
5 req.setTimestamp(c.getTime().getTime()) ;
6 req.setParentCid(new Long(0));
7 ItemcatsGetResponse response=client.execute(req);
8 return response.getItemCats();
调用 taobao.taobaoke.items.get 1 TaobaoClient client=new DefaultTaobaoClient(TaobaokeConstant.SANDBOX_URL, TaobaokeConstant.APP_KEY,TaobaokeConstant.APP_SERCET);
2 TaobaokeItemsGetRequest req=new TaobaokeItemsGetRequest();
3 req.setFields("num_iid,title,nick,pic_url,price,click_url,commission,commission_rate,commission_num,commission_volume,shop_click_url,seller_credit_score,item_location,volume,taobaoke_cat_click_url,keyword_click_url");
4 req.setCid(Long.parseLong(cid));
5 req.setNick(TaobaokeConstant.NICK);
6 req.setSort("commissionRate_desc");
7 TaobaokeItemsGetResponse response=client.execute(req);
8 return response.getTaobaokeItems(); 想用GAE JCache API 加入缓存以减轻压力,但屡试不行,从缓存中取 的时候报错没找到原因 改用自己写的缓存,然后用App Engine Cron 服务管理缓存 corn.xml 1 <?xml version="1.0" encoding="UTF-8"?>
2 <cronentries>
3 <cron>
4 <url>/cron/recache</url>
5 <description>Repopulate the cache every 1 hours</description>
6 <schedule>every 1 hours</schedule>
7 </cron>
8 </cronentries>
2010年10月20日星期三
GWT POST 提交页面
GWT POST 提交页面
将所有参数以&分隔放入builder.setRequestData中
01 RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, BASIC_URL);
02 builder.setHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8");
03 builder.setRequestData("chartSWF=" + be.getSelectedItem().getType() + ".swf&chartId=" + be.getSelectedItem().getType() + "&strXML=" + generateXml(entry));
04 builder.setCallback(new RequestCallback(){
05 public void onError(Request request, Throwable exception) {
06 chart.removeAll();chart.addText("出错啦");
07 }
08 public void onResponseReceived(Request request, Response response) {
09 if(200 == response.getStatusCode()){
10 chart.removeAll();
11 chart.addText(response.getText());
12 chart.layout();
13 }else{
14 chart.removeAll();chart.addText("出错啦");
15 }
16 }
17 });
18
19 try {
20 builder.send();
21 } catch (RequestException e) {
22 e.printStackTrace();
23 }
参考:http://blog.csdn.net/leoyunfei/archive/2008/12/26/3611565.aspx