root/SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/www/CLServlet.java @ 192

リビジョン 175, 3.9 KB (コミッタ: atsuko, 10 年 前)

HttpSession? でデータ共有

行番号 
1/*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6
7package org.biohackathon.SPARQLBuilder.www;
8
9import java.io.IOException;
10import java.io.PrintWriter;
11//import java.math.BigDecimal;
12import javax.json.*;
13import javax.servlet.ServletException;
14import javax.servlet.annotation.WebServlet;
15import javax.servlet.http.HttpServlet;
16import javax.servlet.http.HttpServletRequest;
17import javax.servlet.http.HttpServletResponse;
18import javax.servlet.http.HttpSession;
19import org.biohackathon.SPARQLBuilder.OWL.*;
20
21/**
22 *
23 * @author atsuko
24 */
25@WebServlet(name = "CLServlet", urlPatterns = {"/clist"})
26public class CLServlet extends HttpServlet {
27
28    private static final String FILENAME = "cdata/";
29   
30    /**
31     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
32     * methods.
33     *
34     * @param request servlet request
35     * @param response servlet response
36     * @throws ServletException if a servlet-specific error occurs
37     * @throws IOException if an I/O error occurs
38     */
39    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
40            throws ServletException, IOException {
41        response.setContentType("text/html;charset=UTF-8");
42        try (PrintWriter out = response.getWriter()) {
43            /* TODO output your page here. You may use following sample code. */
44            out.println("<!DOCTYPE html>");
45            out.println("<html>");
46            out.println("<head>");
47            out.println("<title>Servlet CLServlet</title>");           
48            out.println("</head>");
49            out.println("<body>");
50            out.println("<h1>Servlet CLServlet at " + request.getContextPath() + "</h1>");
51            out.println("</body>");
52            out.println("</html>");
53        }
54    }
55
56    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
57    /**
58     * Handles the HTTP <code>GET</code> method.
59     *
60     * @param request servlet request
61     * @param response servlet response
62     * @throws ServletException if a servlet-specific error occurs
63     * @throws IOException if an I/O error occurs
64     */
65    @Override
66    protected void doGet(HttpServletRequest request, HttpServletResponse response)
67            throws ServletException, IOException {
68        //processRequest(request, response);
69        response.setContentType("application/json;charset=UTF-8");
70        PrintWriter out = response.getWriter();
71        String ep = request.getParameter("ep");
72        HttpSession session = request.getSession();
73        QueryPathGenerator qpg = (QueryPathGenerator)session.getAttribute("qpg");
74        if ( qpg == null ){
75        //QueryPathGenerator
76                   qpg = new QueryPathGenerator();
77        }
78        qpg.setSPARQLendpoint(ep);
79        SClass[] classes = qpg.getClasses(null);
80        JsonBuilderFactory jbfactory = Json.createBuilderFactory(null);
81        JsonArrayBuilder jab = jbfactory.createArrayBuilder();
82        for (int i = 0 ; i < classes.length; i++ ){
83            jab.add(classes[i].getClassURI());
84        }
85        JsonArray ja = jab.build();
86        out.print(ja);
87    }
88
89    /**
90     * Handles the HTTP <code>POST</code> method.
91     *
92     * @param request servlet request
93     * @param response servlet response
94     * @throws ServletException if a servlet-specific error occurs
95     * @throws IOException if an I/O error occurs
96     */
97    @Override
98    protected void doPost(HttpServletRequest request, HttpServletResponse response)
99            throws ServletException, IOException {
100        processRequest(request, response);
101    }
102
103    /**
104     * Returns a short description of the servlet.
105     *
106     * @return a String containing servlet description
107     */
108    @Override
109    public String getServletInfo() {
110        return "Short description";
111    }// </editor-fold>
112
113}
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。