package NameService;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class FindNameServlet extends HttpServlet {
private List<String> names = new ArrayList<String>();
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//System.out.println("this is findNameServlet");
String prefix = request.getParameter("names");
//System.out.println(prefix);
NameService service = NameService.getInstance(names);
List matching = service.findNames(prefix);
if(matching.size()>0){
PrintWriter out = response.getWriter();
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Charset", "UTF-8");
response.setCharacterEncoding("UTF-8");
out.println("<response>");
Iterator iter = matching.iterator();
while(iter.hasNext()){
String name = (String) iter.next();
// name = new String(name.getBytes("ISO-8859-1"),"UTF-8");
System.out.println(" ## 匹配查询结果 :"+name);
out.println("<name>"+name+"</name>");
}
out.println("</response>");
matching = null;
service = null;
out.close();
}else{
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
this.doGet(request, response);
}
public void init() throws ServletException {
names.add("中国人民");
names.add("人民币a");
names.add("广东d");
names.add("广东佛山a");
names.add("浦北中学b");
names.add("浦北人b");
names.add("我的浦北世界a");
names.add("美丽的浦北广东a");
names.add("我的故而浦北中国c");
names.add("广西之家b");
names.add("你好,广西a");
names.add("是不是呢");
names.add("来吧,亲");
names.add("a看了");
names.add("abc是的");
names.add("abcdefghigklmnopqrstuvwxyz金正日同志永垂不朽!");
System.out.println("this is init");
System.out.println();
}
}
疯狂拇指
- 粉丝: 25
- 资源: 62
最新资源
- 面向初学者的 Java 教程(包含 500 个代码示例).zip
- 阿里云OSS Java版SDK.zip
- 阿里云api网关请求签名示例(java实现).zip
- 通过示例学习 Android 的 RxJava.zip
- 通过多线程编程在 Java 中发现并发模式和特性 线程、锁、原子等等 .zip
- 通过在终端中进行探索来学习 JavaScript .zip
- 通过不仅针对初学者而且针对 JavaScript 爱好者(无论他们的专业水平如何)设计的编码挑战,自然而自信地拥抱 JavaScript .zip
- 适用于 Kotlin 和 Java 的现代 JSON 库 .zip
- AppPay-安卓开发资源
- yolo5实战-yolo资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页