这是我的代码:
@WebServlet({ "/Response1", "/resp" })
public class Response1 extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
int count=0;
int Number =1;
System.out.println("s val is ==> "+request.getParameter("empidVal"));
String s1 = request.getParameter("empidVal");
System.out.println(s1);
services3 empjiras = new services3();
try {
Map<Object, Object> map1 = empjiras.getJiras(s1);
Object obj3 = map1.get("obj3");
map1.remove("obj3");
System.out.println(obj3);
Collection c=map1.values();
String myvalue="";
for (Iterator iterator = c.iterator(); iterator.hasNext();)
{
myvalue = (String) iterator.next();
count++;
}
System.out.println(count);
int count1 = count;
if(count!=0)
{
Set<Map.Entry<Object,Object>> s2=map1.entrySet();
PrintWriter out1=response.getWriter();
out1.println("<html>"+
"<center><font size=\"20\"><body><h2>JIRA Details</h2></font>"+
//"<table border='1'>"+
"<table width=\"800\" border ='10'>\r\n" +
"<tr>\r\n" +
"<th><font size ='+2'>Number</font></th>"+
"<th><font size ='+2'>JiraNumber</font></th>"+
"<th><font size ='+2'>Jira Status</font></th>" +
"<th><font size = '+2'>EmailId</font></th>\r\n</center>"+
"<button type='ok' value='ok'>OK</button>" +
"<button type='cancel' value='cancel'>cancel</button>");
for (Iterator<Map.Entry<Object,Object>> iterator = s2.iterator(); iterator.hasNext();) {
Map.Entry<Object,Object> entry = iterator.next();
Object name2 = entry.getKey();
Object value2 = entry.getValue();
Object email = obj3;
int num = Number++;
PrintWriter out=response.getWriter();
out.println(
"</tr>\r\n" +
"<tr>\r\n" +
"<tr>\r\n" +
"<td height=\"100\">"+num+"</td>"+
"<td height=\"100\">"+name2+"</td>\r\n" +
"<td height=\"100\">"+value2+"</td>\r\n"+
"<td height=\"100\">"+email+"</td>\r\n"+
"</tr>\r\n");
}
out1.println("</table></body></html>");
}
else
{
PrintWriter out=response.getWriter();
// out.println("count is :"+count1);
out.println("<html><body><h2>no jira issues in validating release</h2></body></html>");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
这里我将html代码嵌入一个我认为不是很好的方法的servlet中,实际上我是从另一个servlet中读取对象,然后对其进行处理并在浏览器中显示它。但是有什么方法可以分开来自servlet的此html代码。 在此先感谢。