首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

有关JAVA的东西求帮助解决办法

2012-02-22 
有关JAVA的东西求帮助public class Test extends HttpServlet {/** * Constructor of the object. */publi

有关JAVA的东西求帮助
public class Test extends HttpServlet {

/**
* Constructor of the object.
*/
public Test() {
super();
}

/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}


public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}


public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html");

if(request.getParameter("path")!=null && !"".equals(request.getParameter("path"))){
PrintWriter out = response.getWriter();
out.print(1123123131);
try{ 
  File f = new File(request.getParameter("path"));
  BufferedReader bufRead = new BufferedReader(new InputStreamReader(new FileInputStream(f))); 
  String str; 
  StringBuffer newstr = new StringBuffer("");
   
  while((str = bufRead.readLine()) != null){ 
  newstr.append(str+"<br>");
 
  }
  String s = str+"<br>";
   
   
  request.setAttribute("content", newstr);
   
  }catch(IOException ioe) {ioe.printStackTrace();}
  getServletConfig().getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
}else{
response.sendRedirect("/servlet/index.jsp");
}

}


public void init() throws ServletException {
// Put your code here
}

}
这段我的写的JAVA方法

但是我要在 while((str = bufRead.readLine()) != null){ 
  newstr.append(str+"<br>");
   
  }加个正则表达式的方法 截取字符串 要怎么+求帮助。

[解决办法]
while((str = bufRead.readLine()) != null){
newstr.append(str+"<br>");
}
楼主首先要看你要过滤什么,你要是过滤特定的字符串,你就可以在while里面加判断,首先判断是否含有你要过滤的字符串,有的话就去掉,就OK了啊,
以上是我说的大概方法,因为楼主说的不够详细,所以我就只能说这些了

热点排行