package com.strain.certificatequery.action;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import com.strain.certificatequery.model.Certificate;
import com.strain.certificatequery.service.impl.CertificateServiceImpl;
import com.strain.common.struts2.action.BaseAction;
@Controller("certificate.certificateaction")
public class CertificateAction extends BaseAction {
private Certificate certificate = new Certificate();
@Autowired
private CertificateServiceImpl certificateServiceImpl;
public Certificate getCertificate() {
return certificate;
}
public void setCertificate(Certificate certificate) {
this.certificate = certificate;
}
public String certificateSelect()
{
String certificateNum = certificate.getCertificateNum();
String type = certificate.getType();
String identityID = certificate.getIdentityID();
System.out.println(type+";"+certificateNum+";"+identityID);
List<Certificate> certificateList = certificateServiceImpl.select(type,identityID,certificateNum);
String s =
"<setCertificate>"+
"<name>"+certificateList.get(0).getName()+"</name>"+
"<certificateNum>"+certificateList.get(0).getCertificateNum()+"</certificateNum>"+
"<certificationTime>"+certificateList.get(0).getCertificationTime()+"</certificationTime>"+
"<rtrainingTime>"+certificateList.get(0).getRtrainingTime()+"</rtrainingTime>"+
"<issuingAuthority>"+certificateList.get(0).getIssuingAuthority()+"</issuingAuthority>"+
"<type>"+certificateList.get(0).getType()+"</type>"+
"<phoneNum>"+certificateList.get(0).getPhoneNum()+"</phoneNum>"+
"<email>"+certificateList.get(0).getEmail()+"</email>"+
"</setCertificate>";
System.out.println(s);
if(certificateList==null)
{
return "error";
}
else
{
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/xml");
response.setCharacterEncoding("GBK");
try {
PrintWriter pw = response.getWriter();
pw.print(s);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "certificateSelect";
}
}
}
以上是action里的代码.....,String s 我是想拼成xml的格式,然后页面上加载,现在遇到这个问题,我页面里没写东西,但是直接就把 s 打印出来了,主要打印的出来的字符串没有了<name></name>.....等这些东西,直接是certificateList.get(0).getName()取到的值!这是什么原因?怎么解决?谢谢!!我浏览器是IE8,不会是浏览器问题吧?