这是我的servlet:
@WebServlet({ "/Response", "/reportsto" })
public class Response extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Response() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
services2 messageservice = new services2();
services3 jiraservice = new services3();
service4 empid = new service4();
String id = request.getParameter("ManagerId");
try {
String name="";
String id1 =empid.getEmpId(id);
System.out.println("id is ===> "+id1);
Map<Object, Object> map=messageservice.getReportees(id1);
Set<Map.Entry<Object,Object>> s1=map.entrySet();
for (Iterator<Map.Entry<Object,Object>> iterator = s1.iterator(); iterator.hasNext();) {
Map.Entry<Object,Object> entry = iterator.next();
Object name1 = entry.getKey();
Object value = entry.getValue();
PrintWriter out=response.getWriter();
out.println("<html><body><table>\r\n" +
"<tr>\r\n" +
"<th>User Id</th>\r\n" +
"<th>Username</th>\r\n" +
"</tr>\r\n" +
"<tr>\r\n" +
"<td>"+value+"</td>\r\n" +
"<td><a href=''>"+name1+"</a></td>\r\n" +
"</tr>\r\n" +
"</table></body></html>");
//how should I pass the object value to getJiras which accepts the strings.
}
I will get the output as:
User Id Username
AR12345 Anagha R
因此,如果我单击Anagha,则必须将用户ID传递给具有返回类型作为Map Object的getJiras,然后它应该处理并显示 CHA-3603:在以上输出的同一页上的浏览器中验证发布。
getJiras()
public class services3{
public Map<Object, Object> getJiras(String values) throws Exception {
String api = "https:*****";
String id = values;
String ext= "******";
String url = api+id+ext;
String name = "******";
String password = "********";
String authString = name + ":" + password;
String authStringEnc = new BASE64Encoder().encode(authString.getBytes());
System.out.println("Base64 encoded auth string: " + authStringEnc);
Client restClient = Client.create();
WebResource webResource = restClient.resource(url);
ClientResponse resp = webResource.accept("application/json")
.header("Authorization", "Basic " + authStringEnc)
.get(ClientResponse.class);
if(resp.getStatus() != 200){
System.err.println("Unable to connect to the server");
}
//here I am trying to parse the json data.
JSONParser parse = new JSONParser();
JSONObject jobj = (JSONObject)parse.parse(output);
JSONArray jsonarr_1 = (JSONArray) jobj.get("issues");
System.out.println("The total number of issues in validating release are:"+jsonarr_1.size());
Map<Object, Object> map=new HashMap<Object,Object>();
for(int i=0;i<jsonarr_1.size();i++){
JSONObject jsonobj_1 = (JSONObject)jsonarr_1.get(i);
JSONObject jsonobj_2 = (JSONObject)jsonobj_1.get("fields");
JSONObject status1 = (JSONObject)jsonobj_2.get("status");
JSONObject issuetype = (JSONObject)jsonobj_2.get("issuetype");
Object obj1 = jsonobj_1.get("key");
Object obj2 = status1.get("name");
map.put(obj1, obj2);
}
return map;
}
我还如何显示浏览器中正在打印的json数组大小。问题日益复杂,请帮助解决此问题。谢谢
答案 0 :(得分:0)
您可以创建另一个servlet或使用相同的servlet再次提出一个get
请求。该请求将调用jira service
。
案例1:创建另一个servlet,它与您正在执行的操作相似
情况2:您可以自定义当前的servlet方法doGet
。示例代码如下。
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String requestAction = request.get("action");
if("detail".equals(requestAction)) {
services3 service = new services3();
//get result.
} else if("view".equals(requestAction)){
//your current code
}
//add result to response
}