Android 开发服务类 02_NewsListServlet
Servlet implementation class NewsListServlet
package com.wangjialin.server.xml; import java.io.IOException;
import java.util.List; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.wangjialin.server.domain.News;
import com.wangjialin.server.service.NewsService;
import com.wangjialin.server.service.implement.NewsServiceBean; /**
* Servlet implementation class NewsListServlet
*/
public class NewsListServlet extends HttpServlet { private static final long serialVersionUID = 1L;
private NewsService newsService = new NewsServiceBean(); protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
} protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { List<News> newes = newsService.getLastNews(); // 获取最新的视频资讯
// [{id:20,title:"xxx",timelength:90},{id:10,title:"xbx",timelength:20}]
StringBuilder json = new StringBuilder();
json.append('['); for(News news : newes){
json.append('{');
json.append("id:").append(news.getId()).append(",");
json.append("title:\"").append(news.getTitle()).append("\",");
json.append("timelength:").append(news.getTimelength());
json.append("},");
}
json.deleteCharAt(json.length() - 1);
json.append(']');
request.setAttribute("json", json.toString());
request.getRequestDispatcher("/WEB-INF/page/jsonnewslist.jsp").forward(request, response);
} }
NewsServiceBean
package com.wangjialin.server.service.implement; import java.util.ArrayList;
import java.util.List; import com.wangjialin.server.domain.News;
import com.wangjialin.server.service.NewsService; public class NewsServiceBean implements NewsService {
/**
* 获取最新的视频资讯
* @return
*/
public List<News> getLastNews(){
List<News> newes = new ArrayList<News>();
newes.add(new News(10, "王家林", 20));
newes.add(new News(45, "家林哥哥", 10));
newes.add(new News(89, "Android is amazing", 50));
return newes;
}
}
NewsService
package com.wangjialin.server.service;
import java.util.List;
import com.wangjialin.server.domain.News;
public interface NewsService {
/**
* 获取最新的视频资讯
* @return
*/
public List<News> getLastNews();
}
News
package com.wangjialin.server.domain;
public class News {
private Integer id;
private String title;
private Integer timelength;
public News(Integer id, String title, Integer timelength) {
this.id = id;
this.title = title;
this.timelength = timelength;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Integer getTimelength() {
return timelength;
}
public void setTimelength(Integer timelength) {
this.timelength = timelength;
}
}
jsonnewslist.jsp
<%@ page language="java" contentType="text/plain; charset=UTF-8" pageEncoding="UTF-8"%>
${json}
itcast.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
传智播客<br/>
传智播客<br/>
传智播客<br/>
传智播客<br/>
传智播客<br/>
传智播客<br/>
传智播客<br/>
传智播客<br/>
传智播客<br/> </body>
</html>
Android 开发服务类 02_NewsListServlet的更多相关文章
- Android 开发服务类 05_ ApkPatchDemo
APP 增量更新服务端[https://github.com/cundong/SmartAppUpdates] import com.cundong.common.Constants; import ...
- Android 开发服务类 04_ServletForPOSTMethod
ServletForPOSTMethod 业务类 package com.wangjialin.internet.servlet; import java.io.IOException; import ...
- Android 开发服务类 01_ServletForXML
Servlet implementation class NewsListServlet package com.wangjialin.server.xml; import java.io.IOExc ...
- Android 开发服务类 03_ServletForGETMethod
接收并处理用户通过 GET 方式上传的数据,一般小于 2K,并且安全性要求不高. package com.wangjialin.internet.servlet; import java.io.IOE ...
- Android开发工具类
7种无须编程的DIY开发工具 你知道几个? 现如今,各种DIY开发工具不断的出现,使得企业和个人在短短几分钟内就能完成应用的创建和发布,大大节省了在时间和资金上的投入.此外,DIY工 具的出现,也帮助 ...
- Android开发——Context类的各种细节问题
0. 前言 Context相信所有的Android开发人员基本上每天都在接触,因为它太常见了.但实际上Context有太多小的细节并不被大家所关注,那么今天我们就来学习一下那些你所不知道的细节. ...
- Android 开发工具类 35_PatchUtils
增量更新工具类[https://github.com/cundong/SmartAppUpdates] import java.io.File; import android.app.Activity ...
- Android 开发 Camera类的拍照与录像
前言 在开发Android应用的时候,如果需要调用摄像头拍照或者录像,除了通过Intent调用系统现有相机应用进行拍照录像之外,还可以通过直接调用Camera硬件去去获取摄像头进行拍照录像的操作.本篇 ...
- Android 开发工具类 27_多线程下载大文件
多线程下载大文件时序图 FileDownloader.java package com.wangjialin.internet.service.downloader; import java.io.F ...
随机推荐
- ILA用法
Ila在使用过程中Capture mode可选, write_hw_ila_data 把从ILA中读出的数据写入文件中. Syntax write_hw_ila_data [-force] [-csv ...
- MATLAB中的快捷键
Ctrl + c 中止程序的运行,鼠标要点到命令窗内.
- (匹配)Antenna Placement --POJ --3020
链接: http://poj.org/problem?id=3020 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82834#probl ...
- hdu 1163 Eddy's digital Roots 【九余数定理】
http://acm.hdu.edu.cn/showproblem.php?pid=1163 九余数定理: 如果一个数的各个数位上的数字之和能被9整除,那么这个数能被9整除:如果一个数各个数位上的数字 ...
- Nonsense Alphabet
Nonsense Alphabet A was an ant Who seldom stood still, And who made a nice house In the side of a hi ...
- Androd Studio测试
测试的分类: 在软件开发领域,程序员开发编码后,需要测试部门的测试,才可以发布软件版本,所以对测试的概念需要了解: 黑盒测试:我的理解是,黑盒测试更多的是体力活,按照测试用例,在屏幕上不停的操作的方式 ...
- matlab 降维工具箱
Matlab Toolbox for Dimensionality Reduction 降维方法包括: Principal Component Analysis (PCA) • Probabili ...
- nginx backend 健康检查
ngx_http_proxy_module 模块和ngx_http_upstream_module模块(自带) 严格来说,nginx自带是没有针对负载均衡后端节点的健康检查的,但是可以通过默认自带的n ...
- python 实现判断一个用户输入字符串是否是小数的小程序
要判断一个字符串是否是小数:1先判断小数点的个数,即如果是小数,则必须有且仅有一个'.'号2再分别判断'.'号的左右两边是否是数字: 判断左边时,如果负数,则左边包含'-'号:必须以'-'号开头(校验 ...
- 使用hadoop-daemon.sh 启动bootstrapStandby nameNode异常
使用hadoop-daemon.sh 启动bootstrapStandby nameNode异常 启动bootstrapStandby nameNode时,直接通过ssh 过去执行该命令,一直无法成功 ...