C# 到 Java 代码
我有一小段用 C# 给出的代码:
protected void Page_Load(object sender, EventArgs e)
{
try{
string sFind = Request.QueryString["F"];
string sFindBy = Request.QueryString["FB"];
Response.ContentType = "text/xml";
//Simulate Resonse (throw exeption on error) -------------------------------->
XmlDocument docRet = new XmlDocument();
XmlElement docElement = (XmlElement)docRet.AppendChild(docRet.CreateElement("Request"));
generateResponseParamss(docElement, "Language", "heb");
generateResponseParamss(docElement, "IMTSI", "972.001.000000081");
generateResponseParamss(docElement, "Mobile", "0544490540");
generateResponseParamss(docElement, "Email", "[email protected]");
generateResponseParamss(docElement, "FirstName", "גדי");
generateResponseParamss(docElement, "LastName", "גדיגדי");
docRet.Save(Response.OutputStream);
}catch(Exception ex){
ShowErrorAsXml(Response, ex);
}
}
public void generateResponseParamss(XmlElement docElement, string sParamsName, string sParamsValue)
{
XmlElement newNode = (XmlElement)docElement.AppendChild(docElement.OwnerDocument.CreateElement("Param"));
newNode.SetAttribute("Name", sParamsName);
newNode.SetAttribute("Value", sParamsValue);
}
我想将此代码转换为 Java,我想我需要创建一个通过 URL 行(“GET”)接收参数的 servlet,但是 C# 代码行我最困难的是:
docRet.Save(Response.OutputStream);
哪个命令在 Java 中执行相同的操作。
I have a small piece of code I was given in C#:
protected void Page_Load(object sender, EventArgs e)
{
try{
string sFind = Request.QueryString["F"];
string sFindBy = Request.QueryString["FB"];
Response.ContentType = "text/xml";
//Simulate Resonse (throw exeption on error) -------------------------------->
XmlDocument docRet = new XmlDocument();
XmlElement docElement = (XmlElement)docRet.AppendChild(docRet.CreateElement("Request"));
generateResponseParamss(docElement, "Language", "heb");
generateResponseParamss(docElement, "IMTSI", "972.001.000000081");
generateResponseParamss(docElement, "Mobile", "0544490540");
generateResponseParamss(docElement, "Email", "[email protected]");
generateResponseParamss(docElement, "FirstName", "גדי");
generateResponseParamss(docElement, "LastName", "גדיגדי");
docRet.Save(Response.OutputStream);
}catch(Exception ex){
ShowErrorAsXml(Response, ex);
}
}
public void generateResponseParamss(XmlElement docElement, string sParamsName, string sParamsValue)
{
XmlElement newNode = (XmlElement)docElement.AppendChild(docElement.OwnerDocument.CreateElement("Param"));
newNode.SetAttribute("Name", sParamsName);
newNode.SetAttribute("Value", sParamsValue);
}
And I would like to turn this code to Java, I think I need to create a servlet that receives parameter through the URL line ("GET"), but the C# code line that I'm most dificult with is:
docRet.Save(Response.OutputStream);
Which command do the same in Java.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看本教程。 搜索
StreamResult结果 = new StreamResult(System.out);
.将该行更改为
new StreamResult(new PrintStream(response.getOutputStream()));
Look at this tutorial. Search for
StreamResult result = new StreamResult(System.out);
.Change that line to have
new StreamResult(new PrintStream(response.getOutputStream()));
有几种方法可以做到这一点。您使用什么类来存储 xml 响应?
There are several ways to do that. What class are you using for storing the xml response?