当前位置: 技术问答>java相关
我的applet无法向ervlet传递参数了!各位大虾救命啊 applet---xml----servlet
来源: 互联网 发布时间:2015-02-18
本文导语: 在IE里直接输入http://111.112.3.12:7001/pooltest4?kind=test时,servlet运行正常,能输出xml.在applet里如下调用时得不到xml,document为null..不知道为什么!!!!大家帮帮我啊 applet端: import org.apache.xerces.framework.XMLParser; import org.a...
在IE里直接输入http://111.112.3.12:7001/pooltest4?kind=test时,servlet运行正常,能输出xml.在applet里如下调用时得不到xml,document为null..不知道为什么!!!!大家帮帮我啊
applet端:
import org.apache.xerces.framework.XMLParser;
import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
{
DOMParser parser = new DOMParser("http://111.112.3.12:7001/pooltest4?kind=test");
try {
parser.parse(xmlFile);
Document document = parser.getDocument();
} catch (Exception e) {
System.err.println (e);
}
}
servlet端:
package examples.jdbc.pool;
import java.io.*;
import java.sql.*;
import java.net.*;
import java.util.Properties;
import javax.servlet.*;
import javax.servlet.http.*;
import weblogic.db.jdbc.*;
import weblogic.html.*;
public class pooltest4 extends HttpServlet
{
public synchronized void service(HttpServletRequest req,HttpServletResponse res)
throws IOException
{
Connection conn = null;
try
{
ServletOutputStream out = res.getOutputStream();
out.print(req.getParameter("kind"));
String kind=req.getParameter("kind");
Properties props = new Properties();
props.put("user", "system");
props.put("password", "12345678");
Driver myDriver = (Driver) Class.forName("weblogic.jdbc.pool.Driver").newInstance();
conn = myDriver.connect("jdbc:weblogic:pool:SQLPool",props);
res.setContentType("text/html");
Statement stmt = conn.createStatement();
if(kind.equals("test")){
stmt.execute("select * from t1");
ResultSet ds = stmt.getResultSet();
ServletPage hp = new ServletPage("Simple select");
(MarkupElement.HorizontalLine).addElement(tbl);
out.print("");
while (ds.next()){
out.print("");
}
out.print("");
ds.close();
}
conn.close();
}
catch (Exception e)
{
ServletPage hp = new ServletPage("An Exception occurred");
ByteArrayOutputStream ostr =new ByteArrayOutputStream();
e.printStackTrace(new PrintStream(ostr));
hp.getBody().addElement(new HeadingElement("An Exception occurred:", 2)).addElement(new LiteralElement(ostr.toString()));
}
}
}
applet端:
import org.apache.xerces.framework.XMLParser;
import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
{
DOMParser parser = new DOMParser("http://111.112.3.12:7001/pooltest4?kind=test");
try {
parser.parse(xmlFile);
Document document = parser.getDocument();
} catch (Exception e) {
System.err.println (e);
}
}
servlet端:
package examples.jdbc.pool;
import java.io.*;
import java.sql.*;
import java.net.*;
import java.util.Properties;
import javax.servlet.*;
import javax.servlet.http.*;
import weblogic.db.jdbc.*;
import weblogic.html.*;
public class pooltest4 extends HttpServlet
{
public synchronized void service(HttpServletRequest req,HttpServletResponse res)
throws IOException
{
Connection conn = null;
try
{
ServletOutputStream out = res.getOutputStream();
out.print(req.getParameter("kind"));
String kind=req.getParameter("kind");
Properties props = new Properties();
props.put("user", "system");
props.put("password", "12345678");
Driver myDriver = (Driver) Class.forName("weblogic.jdbc.pool.Driver").newInstance();
conn = myDriver.connect("jdbc:weblogic:pool:SQLPool",props);
res.setContentType("text/html");
Statement stmt = conn.createStatement();
if(kind.equals("test")){
stmt.execute("select * from t1");
ResultSet ds = stmt.getResultSet();
ServletPage hp = new ServletPage("Simple select");
(MarkupElement.HorizontalLine).addElement(tbl);
out.print("");
while (ds.next()){
out.print("");
}
out.print("");
ds.close();
}
conn.close();
}
catch (Exception e)
{
ServletPage hp = new ServletPage("An Exception occurred");
ByteArrayOutputStream ostr =new ByteArrayOutputStream();
e.printStackTrace(new PrintStream(ostr));
hp.getBody().addElement(new HeadingElement("An Exception occurred:", 2)).addElement(new LiteralElement(ostr.toString()));
}
}
}
|
吃过饭通过程序,看吧
URL url=new URL("http://localhost:8080/servlet/Test");
DataInputStream din=new DataInputStream(url.openStream());
InputSource in=new InputSource(din);
parser.parse(in);
URL url=new URL("http://localhost:8080/servlet/Test");
DataInputStream din=new DataInputStream(url.openStream());
InputSource in=new InputSource(din);
parser.parse(in);