Revision 48
Added by Matt Jones over 24 years ago
MetaCatServlet.java | ||
---|---|---|
6 | 6 |
import javax.servlet.ServletConfig; |
7 | 7 |
import javax.servlet.ServletContext; |
8 | 8 |
import javax.servlet.ServletException; |
9 |
import javax.servlet.ServletInputStream; |
|
9 | 10 |
import javax.servlet.http.HttpServlet; |
10 | 11 |
import javax.servlet.http.HttpServletRequest; |
11 | 12 |
import javax.servlet.http.HttpServletResponse; |
... | ... | |
41 | 42 |
public void doGet (HttpServletRequest request, HttpServletResponse response) |
42 | 43 |
throws ServletException, IOException { |
43 | 44 |
|
44 |
PrintWriter out; |
|
45 |
|
|
46 | 45 |
// Get the parameters from the form |
47 | 46 |
String querystring = request.getQueryString(); |
48 | 47 |
Hashtable params = HttpUtils.parseQueryString(querystring); |
49 |
String[] query = (String[])params.get("query"); |
|
50 | 48 |
|
49 |
// Process the data and send back the response |
|
50 |
handleGetOrPost(response, params); |
|
51 |
} |
|
52 |
|
|
53 |
public void doPost( HttpServletRequest request, HttpServletResponse response) |
|
54 |
throws ServletException, IOException { |
|
55 |
|
|
56 |
// Get the input data from the client |
|
57 |
ServletInputStream in = request.getInputStream(); |
|
58 |
int len = request.getContentLength(); |
|
59 |
|
|
60 |
// Parse the input data into a Hashtable |
|
61 |
Hashtable params = HttpUtils.parsePostData(len, in); |
|
62 |
|
|
63 |
// Process the data and send back the response |
|
64 |
handleGetOrPost(response, params); |
|
65 |
} |
|
66 |
|
|
67 |
private void handleGetOrPost(HttpServletResponse response, Hashtable params) |
|
68 |
throws ServletException, IOException { |
|
69 |
|
|
51 | 70 |
// Run the query |
71 |
String[] query = (String[])params.get("query"); |
|
52 | 72 |
Hashtable nodelist = queryobj.findRootNodes(query[0]); |
53 | 73 |
|
54 | 74 |
// set content type and other response header fields first |
55 | 75 |
response.setContentType("text/xml"); |
56 | 76 |
|
57 | 77 |
// then write the data of the response |
58 |
out = response.getWriter(); |
|
78 |
PrintWriter out = response.getWriter();
|
|
59 | 79 |
|
60 | 80 |
// Print the reulting root nodes |
61 | 81 |
long nodeid; |
... | ... | |
71 | 91 |
|
72 | 92 |
out.close(); |
73 | 93 |
} |
74 |
|
|
75 |
public void doPost( HttpServletRequest request, HttpServletResponse response) |
|
76 |
throws ServletException, IOException { |
|
77 |
|
|
78 |
PrintWriter out; |
|
79 |
// set content type and other response header fields first |
|
80 |
response.setContentType("text/html"); |
|
81 |
|
|
82 |
// then write the data of the response |
|
83 |
out = response.getWriter(); |
|
84 |
out.println("POST detected"); |
|
85 |
out.close(); |
|
86 |
} |
|
87 |
|
|
88 | 94 |
} |
Also available in: Unified diff
continued work on interface to servlet