import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class getShohi extends HttpServlet {
/*
* サーブレットが入ってくるところ<BR>
*/
public void service(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
//==============================================//
// 前処理:データをハッシュマップに全部入れる //
//==============================================//
HashMap map = new HashMap();
//セッション開始
HttpSession session = request.getSession(true);
// セッションのデータを全部ハッシュマップに移す
Enumeration namelist = session.getAttributeNames();
if ( namelist != null )
{
while(namelist.hasMoreElements() == true )
{
String key = (String)namelist.nextElement();
key = new String(key);
map.put(key,session.getAttribute(key));
}
}
// 画面からのrequestデータを全部ハッシュマップに入れる
request.setCharacterEncoding("utf-8");
Enumeration namelist2 = request.getParameterNames();
if ( namelist2 != null )
{
while(namelist2.hasMoreElements() == true )
{
String key = (String)namelist2.nextElement();
key = new String(key);
map.put(key,request.getParameter(key));
}
}
//==============================//
// 主処理:処理を実行する //
//==============================//
Shohizei obj = new Shohizei();
Vector kekka = obj.select(map);
//==============================//
// 後処理:結果をセットする //
//==============================//
// (1)セッションセット
String[] mapKeyList = (String [])map.keySet().toArray();
for(int i = 0 ; i < mapKeyList.length ; i ++ )
{
if ( mapKeyList[i].indexOf("*session") >= 0 )
{
session.setAttribute(mapKeyList[i],map.get(mapKeyList[i]));
}
}
// (2)結果をXMLで返す
// (2)-1 ContentTypeを設定
response.setContentType("text/xml; charset=utf-8");
response.addHeader("Cache-Control", "no-cache");
response.addHeader("Pragma", "no-cache");
// (2)-2 出力用PrintWriterを取得
PrintWriter out = response.getWriter();
// (2)-3 出力
out.println("<?xml version='1.0' encoding='UTF-8' ?>");
out.println("<kekka xml:lang='ja'>");
if ( kekka == null )
{
out.println("<retcode>-1</retcode)");
}
else
{
out.println("<retcode>0</retcode)");
for(int i = 0 ; i < kekka.size() ; i ++ )
{
HashMap rec = (HashMap)kekka.elementAt(i);
out.println("<item>");
String[] key = (String[])rec.keySet().toArray(new String[0]);
for(int j = 0 ; j < key.length ; j ++ )
{
out.println("<"+ key[i] + ">");
out.println(rec.get(key[i]).toString());
out.println("</"+ key[i] + ">");
}
out.println("</item>");
}
}
out.println("</kekka>");
}
}
|