标题:这个程序能不能在JBuilder9下面实现
只看楼主
luchang999
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2007-6-23
 问题点数:0 回复次数:0 
这个程序能不能在JBuilder9下面实现

我用的是JBuilder9和SQL2000请问

/*
* CountyServlet.java
*
* Created on 2007年6月13日, 上午9:02
*/

package com;

import com.bean.County;
import com.sun.org.apache.bcel.internal.generic.AALOAD;
import java.io.*;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.JspWriter;

/**
*
* @author asd
* @version
*/
public class CountyServlet extends HttpServlet {

/** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=gbk");
List list = new ArrayList();
String[] checks = request.getParameterValues("country");//取得选择的国家名
if(checks!=null) {
for (int i = 0; i < checks.length; i++) {
County county = new County();
county.setName(checks[i]);//国家名,根据选择得到
county.setCode(1);//国家代码,根据数据库得到
list.add(county);
}
}
StringBuffer buffer = new StringBuffer();
if(checks!=null) {
for (int i = 0; i < checks.length; i++) {
buffer.append(checks[i] + ",");
}
}
PrintWriter writer = response.getWriter();
writer.println(buffer.toString());
writer.flush();
writer.close();
}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/** Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/** Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/** Returns a short description of the servlet.
*/
public String getServletInfo() {
return "Short description";
}
// </editor-fold>
}

/*
* Main.java
*
* Created on 2007年6月18日, 下午10:55
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package client;

import java.awt.BorderLayout;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;

/**
*
* @author admin
*/
public class Main {

/** Creates a new instance of Main */
public Main() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
/*这个串要根据配置自行更改。8484是端口号,假设选择了中国、日本、英国3个国家*/
String loginInfo = "http://localhost:8084/WebApplication1/CountyServlet?country=China&country=Japan&country=England";
HttpURLConnection h = (HttpURLConnection) (new URL(loginInfo).openConnection());
InputStream input = h.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(input));
StringBuffer sb = new StringBuffer();
String str1;
while ((str1 = br.readLine()) != null) {
sb.append(str1);
}
String str = sb.toString();
List list = new ArrayList();
StringTokenizer st = new StringTokenizer(str,",");
while(st.hasMoreTokens()) {
list.add(st.nextToken());
}
if(list.isEmpty()){
return;
}
Object[][] data = new Object[list.size()][2];
for(int i = 0;i<list.size();i++) {
data[i][0] = list.get(i);
data[i][1] = "1";
}
JFrame frm = new JFrame();
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTable table = new JTable(data,new Object[]{"国家名","国家代码"});
JScrollPane jp = new JScrollPane(table);
frm.add(jp,BorderLayout.CENTER);
frm.pack();
frm.setVisible(true);
}

}
能在这2个软件下实现吗?
要是能的话请各位前辈给个意见应该怎样操作





搜索更多相关主题的帖子: JBuilder 
2007-06-23 14:27



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-149712-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.895484 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved