testchineseservlet.java

来自「数字图书馆的互操作接口」· Java 代码 · 共 84 行

JAVA
84
字号
package dli2fe.test;import javax.servlet.*;import javax.servlet.http.*;import java.io.*;import java.util.*;/** * Title:        Digial Library Interoperable Interface Fudan Edition * Description:  This project contains all the classes required for DLI2FE interface. Developers use these classes to implement the wrapper and client side codes. The basic functions of DLI2FE is as follows: * Search: Search a digital library source site. * Metadata: Fetch metadata for a site. * ResultAccess: Get results for a given query. * DLI2FE uses Dublin Core as the basic attribute model, DAV/DASL as the general XML-based query language and CORBA as distributed object transportation mechanism. * Copyright:    Copyright (c) 2001 * Company:      Fudan University * @author Carl Tao * @version 1.0 */public class TestChineseServlet extends HttpServlet {  private static final String CONTENT_TYPE = "text/html; charset=GBK";  /**Initialize global variables*/  public void init() throws ServletException {  }  /**Process the HTTP Get request*/  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    String yourName = "";    response.setLocale(Locale.PRC);       // to show Chinese character correctly    response.setContentType(CONTENT_TYPE);    PrintWriter out = response.getWriter();    out.println("<html>");    out.println("<body>");    out.println("<head>");    out.println("<title>Chinese Test for Servlet</title>");    out.println("</head>");    out.println("<body bgcolor=\"white\">");    out.println("<h3>Chinese Test for Servlet</h3>");    try {      yourName = request.getParameter("yourname");      yourName = new String(notNull(yourName).getBytes("ISO-8859-1"));   // convert to platform's default encodings    }    catch(Exception e) {      e.printStackTrace();    }    out.println("本次输入的参数:<br>");    if (yourName != null) {        out.println("你的名字=");        out.println(yourName + "<br>");    } else {        out.println("无参数输入。");    }    out.println("<P>");    out.print("<form action=\"");    out.print("/TestChinese/testchineseservlet\" ");    out.println("method=POST>");    out.println("你的名字:");    out.println("<input type=text size=20 name=yourname>");    out.println("<br>");    out.println("<input type=submit>");    out.println("</form>");    out.println("</body>");    out.println("</html>");  }  public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    doGet(request, response);  }  String notNull(String s) {    return s == null ? "" : s;  }  /**Clean up resources*/  public void destroy() {  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?