关于一个servlet写入信息的程序有问题,希望servlet高手前来解答~~小弟谢谢了~~!!

SWQQ- 2009-04-21 04:15:24
这是servlet程序~!!!
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Survetswq extends HttpServlet {
FileWriter resultsFile;
PrintWriter toFile;
private static final int TIMES=0;
public static int times;
public void init()throws ServletException{
if(getInitParameter("times")!=null){
try{
this.times=Integer.parseInt(getInitParameter("times"));
}catch(NumberFormatException e){
this.times=this.TIMES;
}

}
}

public void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

res.setContentType("text/html;charset=\"gb2312\"");
PrintWriter toClient= res.getWriter();
try{
String surveyName=req.getParameterValues("survey")[0];
resultsFile=new FileWriter(System.getProperty("file.separator")
+"SurveyResult.txt",true);
toFile=new PrintWriter(resultsFile);

toFile.println("数据"+(++times)+":");
Enumeration values=req.getParameterNames();
while(values.hasMoreElements()){
String name=(String)values.nextElement();
String value=req.getParameterValues(name)[0];
value=new String(value.getBytes("8859_1"),"gb2312");
if(name.compareTo("submit")!=0){
toFile.println(name+":"+value);
}
}
toFile.println("");
resultsFile.close();

toClient.println(" <html>");
toClient.println(" <title>完成 </title>");
toClient.println(" <h1>数据已提交谢谢合作 </h1>");
toClient.println(" <br> <br>");
toClient.println("此页已经被访问了 <b> <font color=\"red\">"+times+" </font> </b>次");
toClient.println(" <html>");
}catch(IOException e){
e.printStackTrace();
toClient.println("出错,请重试!");
}
toClient.close();
}
public String getServlentInfo(){
return "Survey Servet Version 1.0";
}
public void destory(){
try{
resultsFile=new FileWriter(System.getProperty("file.separator")
+"SurveyResult.txt",true);
PrintWriter toFile=new PrintWriter(resultsFile);

toFile.println("Survey被访问了"+times+"次");
resultsFile.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
这是一个关于把用户提交的数据写入本机的文件当中~~如果改为把用户提交的数据写入用户的电脑中的某个文件应该怎么改~~网络路径应该怎样改~~在知道用户的IP 地址 主机名字的情况 下~~应该怎么改~?希望高手前来解答~
这是主页面的代码
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class survey extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

res.setContentType("text/html;charset=\"gb2312\"");
PrintWriter out = res.getWriter();
out.println(" <html>");
out.println(" <HEAD> <TITLE>Survey </TITLE> </HEAD>");
out.println(" <BODY>");
out.println(" <form action=http://127.0.0.1:8080/Jsp/servlet/Survetswq method='post'>");
out.println(" <input type=hidden name=survey value=SurveyResult>");
out.println(" <br> <br>你们公司的人数范围是:");
out.println(" <br>1-100 <input type=radio name=employee value=1-100>");
out.println(" <br>100-500 <input type=radio name=employee value=100-500>");
out.println(" <br>500-1000 <input type=radio name=employee value=500-1000>");
out.println(" <br>1000-more <input type=radio name=employee value=1000-more>");


out.println(" <br> <br> <br>你们公司主要的开发语言是:");
out.println(" <br>ASP <input type=radio name=Web_language value=ASP>");
out.println(" <br>PHP <input type=radio name=Web_language value=PHP>");
out.println(" <br>JSP <input type=rado name=Web_language value=JSP>");

out.println(" <br> <br> <br>其他说明:");
out.println(" <br> <input type=text name=comment>");

out.println(" <br> <br> <input type=submit> <input type=reset>");
out.println(" </form>");
out.println(" </BODY>");
out.println(" </HTML>");
}

...全文
101 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
zoutuo 2009-04-22
  • 打赏
  • 举报
回复
没看懂,是谁提交给谁?
ben0759 2009-04-22
  • 打赏
  • 举报
回复
QQ是用c++写出来的基于C/s模式的软件,我们为什么需要下载,就是因为C++做出来的软件有很多底层的设置,能够控制操作系统,而
java ee只是企业级的应用,是基于http协议的,http协议是无状态协议,只能通过客户端向服务器端发送请求,而不能通过服务器端主动向客户端发送请求,
也就是说,没办法主动去拿客户端的系统的硬盘位置,除非楼主有办法让客户端主动把位置发送过来。
Study_Work_2009 2009-04-22
  • 打赏
  • 举报
回复
倾听-csdn 2009-04-22
  • 打赏
  • 举报
回复
还没有搞定吗?

给你推荐一个群吧QQ群:76208671
jinxfei 2009-04-21
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 ghostgant 的回复:]
不可以吗??

为什么个人的qq 信息可以保存到客户机和服务器

期待高手!!!
[/Quote]

QQ的信息保存到客户机,用的应该是Cookie,或者你说的是QQ软件,那当然可以了?
ghostgant 2009-04-21
  • 打赏
  • 举报
回复
不可以吗??

为什么个人的qq 信息可以保存到客户机和服务器

期待高手!!!
patrick002 2009-04-21
  • 打赏
  • 举报
回复
servlet是服务器端技术
在客户端不能使用的
qiyuan371 2009-04-21
  • 打赏
  • 举报
回复
是什么问题哦,这么多好难看啊
Dantin 2009-04-21
  • 打赏
  • 举报
回复
哪有WEB服务可以控制客户端行为的。。。
lovingpig 2009-04-21
  • 打赏
  • 举报
回复
你可以把这些东西写到Cookie上,
如果能在servlet上操作客户端文件, 那一个页面岂不是能把你电脑上的东西全部删除了么
lxy149434823 2009-04-21
  • 打赏
  • 举报
回复
servlet是在服务器上的,不能控制客户端

67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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