Applet 调用servlet的问题

bw1996 2005-04-05 01:05:36
请问,Applet中的button如何调用servlet中的发法
...全文
147 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
bw1996 2005-04-05
  • 打赏
  • 举报
回复
applet和servloet不在同一个war里,但是在同一个Web Application Modules不知跟这个有什么关系啊
bw1996 2005-04-05
  • 打赏
  • 举报
回复
1、servlet的程序
public void doGet(HttpServletRequest request,
HttpServletResponse response){
try{
//String strName = (String)request.getAttribute("name");
System.out.println("HttpServlet*******************************");
String strName = request.getParameter("name");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<hl>");
out.println("hello1 "+strName+",here<br>");
out.println(new Date());
out.println("</hl>");
out.println("</body>");
out.println("</html>");
}catch(Exception ex){
ex.printStackTrace();
}
}
单独运行applet和servlet都正常
2、还有在我把url改成www.google.com的时候,显示Applet不能访问的错误,我想知道,以后我的applet和servlet如果不在同一台机器上的时候,会不会出现同样的问题
bw1996 2005-04-05
  • 打赏
  • 举报
回复
显示错误如下:
没有结果!java.io.IOException: Server returned HTTP response code: 405 for URL: http://localhost:7001/slTest1War/hi?name=Binwei
zhang21cnboy 2005-04-05
  • 打赏
  • 举报
回复
使用xml通信
F1in2003 2005-04-05
  • 打赏
  • 举报
回复
学习一下
剑事 2005-04-05
  • 打赏
  • 举报
回复
public String postURL(String URL,String param)
{
String result="";
try{
URL httpurl = new URL(URL);
HttpURLConnection httpConn = (HttpURLConnection)httpurl.openConnection();
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
PrintWriter out = new PrintWriter(httpConn.getOutputStream());
out.print(param);
out.flush();
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
String line;
while ((line = in.readLine())!= null)
{
result += line; //.substring(line.indexOf("|")+1)
}
in.close();
}catch(Exception e){
result="没有结果!"+e;
}
str=result;
System.out.println(URL);
return result;
}

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧