xml|生成xml|数据|数据库6.3.2.Servlet源码
1.RefreshServlet.java
package com.sitechasia;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import sun.jdbc.rowset.*;
import javax.sql.*;
import javax.rmi.*;
import javax.naming.*;
import weblogic.html.*;
import com.sitechasia.ejb.*;
public class RefreshServlet extends HttpServlet {
PrintWriter out;
ResultEdit re;
private static final String CONTENT_TYPE = "text/html";
private Object ref;
private static String querySQL = null;
private static String HostIP = null;
private static String HostPort = null;
public void init() throws ServletException {
}
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try{
response.setContentType(CONTENT_TYPE);
out = response.getWriter();
HttpSession session=request.getSession(true);
if (request.getMethod().equals("POST")){
querySQL = request.getParameter("sql");
HostIP = request.getParameter("ip");
HostPort = request.getParameter("port");
Context ctx =getInitialContext(HostIP,HostPort);
ref = ctx.lookup("ResultEdit");
ResultEditHome home = (ResultEditHome) PortableRemoteObject.narrow(ref, ResultEditHome.class);
re = home.create();
re.setRowSet(querySQL);
session.setAttribute("ResultEditHandle",re.getHandle());
session.setAttribute("ResultEditHostIP",HostIP);
session.setAttribute("ResultEditHostPort",HostPort);
}
if (session.getAttribute("ResultEditHandle")!=null){
out.println("<html><head><title>Enter</title><META HTTP-EQUIV='Refresh' CONTENT='2;url=/xmltree/index.html'/></head>");
out.println("<body>");
out.println("<p><p><p><center>Refresh......go to XMLServlet</center></p></p></p></body></html>");
}
else {
out.println("<html><head><title>no EJB message</title><META HTTP-EQUIV='Refresh' CONTENT='2;url=/RefreshPost.html'/></head>");
out.println("<body>");
out.println("<p><p><p><center>Refresh...... return RefreshPost.html</center></p></p></p></body></html>");
}
}
catch(Exception e){
System.out.println("error:"+e.getMessage());
e.printStackTrace();
}
}
static public Context getInitialContext(String host,String port) throws Exception {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL,"t3://"+host+":"+port);
return new InitialContext(p);
}
static public Context getInitialContext() throws Exception {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL,"t3://127.0.0.1:80");
return new InitialContext(p);
}
}
用Java实现可保存状态的数据库生成XML树,源码来了(9)
80酷酷网 80kuku.com