applet向servlet傳送資料出現問題

wltop800發表於2004-06-01
我的applet一部分程式碼為:
try
{
SQueryString = workFlowName + "*" + workflowdb;
SQueryString = SQueryString + ("*" + graphPanel.retxml());
URL servlet = new URL(hostAdd+ "/servlet/ServletWorkFlowAnalysis");
System.out.println(getCodeBase());
URLConnection connection = servlet.openConnection();
connection.setDoOutput(true);
OutputStream output =connection.getOutputStream();
output.write(SQueryString.getBytes());
output.flush();
output.close();
}
我的servlet程式碼一部分程式碼為:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
String xmlStr = "";
String workflowdb = "";
try
{

ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
int streamSize = request.getIntHeader("Content-length");
ServletInputStream in =request.getInputStream();
byte bytes[] = new byte[streamSize];
in.read(bytes);
String getStr = new String(bytes);
int LSort = 0;
StringTokenizer ListToken = new StringTokenizer(getStr, "*");
String ATemp[] = new String[4];
while(ListToken.hasMoreElements())
{
String STemp = (String)ListToken.nextElement();
ATemp[LSort] = STemp;
LSort++;
}
workflowname = ATemp[0];
workflowdb = ATemp[1];
xmlStr = ATemp[2];

}
catch(Exception e)
{
e.printStackTrace();
}


我的目的是將applet中的SQueryString字元傳傳入servlet,然後servlet做相應的事情。但是我執行applet後連線servlet時,伺服器根本沒反映,
applet做到後面的事情時,servlet根本都沒載入,這是一個往servlet裡寫資料的程式,不知道為什麼不成功,但是我寫的從servlet裡面讀字串的例子就是成功的,我估計是兩邊的流的控制不對,但不知道怎麼寫,望高手指點一二!
在此謝謝了!

相關文章