关闭

jsp修改example5-6

168人阅读 评论(0) 收藏 举报
分类:
<%@page contentType="text/html;charset=GB2312" %>

<html><body>
<form action="savemessage.jsp" method=post name=form>
<br><br>
<br>姓名<INPUT type="text" name="b"><br>
<br>身高<INPUT type="text" name="a"><br>
<br>年龄<INPUT type="text" name="c"><br>
<br><input type="submit"value="提交内容"name="submit">
</form>
<form action="showmessage.jsp" method=post name=form>
<input type="submit"value="查看内容"name="submit1">
</form>

</body></html>
savemassage.jsp
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import ="java.io.*" %>
<HTML><BODY bgcolor=cyan><FONT size=2>
<% 
String s= request.getParameter("b");
String s1= request.getParameter("a");
String s2= request.getParameter("c");
 File dir=new File("D:/","Students");
    dir.mkdir();
    File f=new File(dir,"hello.txt");
    try{
        FileOutputStream  outfile=new FileOutputStream(f);
        BufferedOutputStream bufferout=new BufferedOutputStream(outfile);
       String ss="<table border=2><tr><th>姓名<th>身高<th>年龄</tr>"+"<td>"+s+"</td>"+"<td>"+s1+"</td>"+"<td>"+s2;
    byte c[]=ss.getBytes();
          bufferout.write(c);
        bufferout.flush();
        bufferout.close();
        outfile.close();
       
           out.print("保存成功!");
       
    }
    catch(IOException e){}
%>
</FONT></BODY></HTML>

showmessage.jsp
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import ="java.io.*" %>
<HTML><BODY bgcolor=cyan><FONT size=2>
<%  
    File f= new File("D:/Students/hello.txt");
    StringBuffer s=new StringBuffer();
    try{
        FileReader  outfile=new FileReader(f);
        BufferedReader bufferin=new BufferedReader(outfile);
        
     
           String temp;
           
           while((temp=bufferin.readLine())!=null)
           s.append(temp);
           
        bufferin.close();
           outfile.close();
           out.print(s); 
      
    }
    catch(IOException e){}
%>
</FONT></BODY></HTML>


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:16456次
    • 积分:540
    • 等级:
    • 排名:千里之外
    • 原创:39篇
    • 转载:1篇
    • 译文:0篇
    • 评论:2条
    文章分类
    最新评论