永发信息网

struts2 Action里打印字符串到页面的问题 高手帮忙

答案:1  悬赏:10  手机版
解决时间 2021-08-15 17:24
  • 提问者网友:难遇难求
  • 2021-08-15 05:06

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,不会是浏览器问题吧?

最佳答案
  • 五星知识达人网友:怀裏藏嬌
  • 2021-08-15 06:05

应该把“<”换成“&lt; ”,把“>”换成“&gt;”

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯