ajax + web service交互架构
<div class="blogstory">用ajax结构直接与axis2提供的web service交互。
[*]环境要求
axis2 v1.4.1(eclipse v3.5的axis2插件只支持到该版本,别用1.5)
eclipse v3.5
[*]生成web服务
用eclipse新建"动态web项目",再新建你的web服务类,最后在右键点类名,菜单中选最下面的web service。按向导下去就成了。
注意首次用会提示要指定axis2的路径,从网上下个bin包,解开。然后再eclipse下的“首选项-axis2”中指定下目录。
public class Article {/** * 内容体获取关联信息 * @param contentId关联体序号 * @return */public ArticleInfo getContentInfoByConentId(long contentId){System.out.println("contentId:"+contentId);ArticleInfo info = new ArticleInfo();info.setBrowseTimes(1000);info.setCommentNum(20);info.setContentId(1);info.setTitle("测试标题");MemberInfo author= new MemberInfo();author.setNikeName("昵称");info.setAuthor(author);List<ArticleComment> list= new ArrayList<ArticleComment>();ArticleComment comment = new ArticleComment();comment.setContent("匿名评论:)good!< img src='1.jpg' />");comment.setAnonymity(true);comment.setCommenter("王一");comment.setContentId(100);comment.setCommentId(1);list.add(comment);comment = new ArticleComment();comment.setContent("署名评论:)good!<img src="2.jpg" mce_src="2.jpg" />");comment.setAnonymity(false);comment.setCommenter("张三");comment.setContentId(100);comment.setCommentId(2);list.add(comment);info.setComments(list);info.setScores(new int[]{1,2,3});return info;}/** * 获取单篇内容体评论 * @param contentId * @return */public List<ArticleComment> getComments(long contentId){System.out.println("contentId:"+contentId);List<ArticleComment> list=new ArrayList<ArticleComment>();ArticleComment comment = new ArticleComment();comment.setContent("匿名评论:)good!<img src="1.jpg" mce_src="1.jpg" />");comment.setAnonymity(true);comment.setCommenter("王一");comment.setContentId(100);comment.setCommentId(1);list.add(comment);comment = new ArticleComment();comment.setContent("署名评论:)good!<img src="2.jpg" mce_src="2.jpg" />");comment.setAnonymity(false);comment.setCommenter("张三");comment.setContentId(100);comment.setCommentId(2);list.add(comment);return list;}/** * 添加评论 * @param contentId 内容 * @param commenter * @param isAnonymity * @param content * @param citation * @return */public boolean addComment(long contentId,long commenter,boolean isAnonymity,String content,String citation){System.out.println("contentId:"+contentId);System.out.println("commenter:"+commenter);System.out.println("isAnonymity:"+isAnonymity);System.out.println("content:"+content);System.out.println("citation:"+citation);return true;}}public class ArticleInfo {long contentId;String title;int commentNum;long browseTimes;int[] scores;public int[] getScores() {return scores;}public void setScores(int[] scores) {this.scores = scores;}List<ArticleComment> comments;MemberInfo author;MemberInfo supp;public MemberInfo getSupp() {return supp;}public void setSupp(MemberInfo supp) {this.supp = supp;}public List<ArticleComment> getComments() {return comments;}public void setComments(List<ArticleComment> comments) {this.comments = comments;}public MemberInfo getAuthor() {return author;}public void setAuthor(MemberInfo author) {this.author = author;}public long getContentId() {return contentId;}public void setContentId(long contentId) {this.contentId = contentId;}public String getTitle() {return title;}public void setTitle(String title) {this.title = title;}public int getCommentNum() {return commentNum;}public void setCommentNum(int commentNum) {this.commentNum = commentNum;}public long getBrowseTimes() {return browseTimes;}public void setBrowseTimes(long browseTimes) {this.browseTimes = browseTimes;}}public class ArticleComment {long contentId;long commentId;String commenter;String content;boolean anonymity;public long getContentId() {return contentId;}public void setContentId(long contentId) {this.contentId = contentId;}public long getCommentId() {return commentId;}public void setCommentId(long commentId) {this.commentId = commentId;}public String getCommenter() {return commenter;}public void setCommenter(String commenter) {this.commenter = commenter;}public String getContent() {return content;}public void setContent(String content) {this.content = content;}public boolean isAnonymity() {return anonymity;}public void setAnonymity(boolean anonymity) {this.anonymity = anonymity;}}public class MemberInfo {private String nikeName;public String getNikeName() {return nikeName;}public void setNikeName(String nikeName) {this.nikeName = nikeName;}private String name;}
[*]参考
可参考以下文章。原文提供的js中有些问题,如不支持boolean型、XSL解析、prototype1.6.1等。
使用 Ajax 调用 SOAP Web 服务,第 1 部分 构建 Web 服务客户机.htm
http://www.ibm.com/developerworks/cn/webservices/ws-wsajax/
使用 Ajax 调用SOAP Web 服务,第 2 部分 扩展 Web 服务客户机.htm
http://www.ibm.com/developerworks/cn/webservices/ws-wsajax2/index.html
[*]与firefox兼容性
IE支持document.frames['xxx']、document.frames('xxx')
firefox支持frames['xxxx']
页:
[1]