我试图通过在jsp中编写一些代理代码,从我的计算机本地对其他域进行ajax调用。这是我调用proxy.jsp页面的jQuery AJAX代码。
var metadata = 'https://rest-search.host.com/machine/search/meta?id=';
var on_show_info= function() {
var AjaxCall = data + current_doc_info.id;
alert(AjaxCall);
request_meta_info = $.ajax({
url: "proxy.jsp?url=" + AjaxCall,
type: 'GET',
success: check,
error: error
});
};
我的JSP文件是: -
<%@ page language="java" import="org.w3c.dom.*,javax.xml.parsers.DocumentBuilder,javax.xml.parsers.DocumentBuilderFactory,java.net.*,java.io.*" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%
String urlToQuery = request.getParameter("url");
System.out.println("rj " +urlToQuery);
URL url = new URL(urlToQuery);
final String login ="user";
final String password ="pass";
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication (login, password.toCharArray());
}
});
URLConnection conn = url.openConnection();
InputStream in = conn.getInputStream();
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db =dbf.newDocumentBuilder();
Document doc=db.parse(urlToQuery);
NodeList nl= doc.getElementsByTagName("attr");
%>
<%= nl.item(0).getFirstChild().getNodeValue() %>
当我检查响应时,我收到它正在解析的XML文件的错误:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Error 500 White spaces are required between publicId and systemId.</title>
</head>
<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing /proxy.jsp. Reason:
<pre> White spaces are required between publicId and systemId.</pre></p><h3>Caused by:</h3><pre>org.xml.sax.SAXParseException: White spaces are required between publicId and systemId.
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:180)
at org.apache.jsp.proxy_jsp._jspService(org.apache.jsp.proxy_jsp:70)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:486)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:380)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:327)
at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:126)
at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:213)
at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:171)
at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:381)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:67)
at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:122)
at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:110)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:536)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:915)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:539)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:405)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
</pre>
<hr /><i><small>Powered by Jetty://</small></i><br/>
</body>
</html>
XMl文件是这样的: -
<results><result><attr value="HW/SW" name="Line"/><attr value="ASIC" name="Description"/><attr value="CD" name="Number"/><attr value="AS" name="DocumentType"/><attr value="" name="Date"/><</result></results>
我在这里做错了什么......任何建议都将受到赞赏..
答案 0 :(得分:31)
如果不明显,错误消息实际上是正确的。它表示您的DOCTYPE必须具有SYSTEM标识符。我认为你的只有一个公共标识符。
你会得到错误(例如):
<!DOCTYPE persistence PUBLIC
"http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
你不会:
<!DOCTYPE persistence PUBLIC
"http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" "">
在第二个结尾处注意""
- 这是系统标识符。错误消息令人困惑:它应该说您需要系统标识符,而不是需要publicId和(不存在的)systemId之间的空格。
顺便说一句,一个空的系统标识符可能不太理想,但它可能足以让你移动。
答案 1 :(得分:2)
我刚刚发现了这个异常,我试图使用JAX-WS,并使用这样的自定义URL:
String WSDL_URL= <get value from properties file>;
Customer service = new Customer(new URL(WSDL_URL));
ExecutePtt port = service.getExecutePt();
return port.createMantainCustomers(part);
和Java扔了:
XML reader error: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,63]
Message: White spaces are required between publicId and systemId.
事实证明,用于构建服务的URL字符串缺少&#34;?wsdl&#34;在末尾。 例如:
为:
http://www.host.org/service/Customer
好:
http://www.host.org/service/Customer?wsdl
答案 2 :(得分:1)
这里的几个人通过在XML文件中切换线条获得了成功。
答案 3 :(得分:1)
更改声明的顺序。 对我来说,更改代码块
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/context
http://www.springframework.org/schema/beans/spring-beans.xsd"
带
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context"
有效。
答案 4 :(得分:0)
如果您在某个网络中工作,需要您在浏览器中使用代理连接到互联网(可能是办公楼),那可能就是这样。我有同样的问题,并将代理配置添加到网络设置解决了它。
如果您不知道代理网址和端口,请与您的网络管理员联系。
答案 5 :(得分:0)
可能与打开标题的人的错误无关,但我想分享它,因为它和标题一样错误。
这是我在使用 netbeans 和 maven 在 glassfish 服务器上运行 jsf primeface 时遇到的错误。
这是让我失败的方式:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
但我是这样返回的,我没有收到任何错误:
<!DOCTYPE html>