提交表单生成html文件的实例方案

发布时间:2020-03-24编辑:脚本学堂
提交表单生成html文件有哪些方法?下面介绍一实用例子,有兴趣的朋友请参考,希望可以帮助到你。

1、test.html
Java代码
文本格式复制代码打印?
 

复制代码 代码示例:
1.<html>
2.<body>
3.<form name = "form1" method = "post" action = "test.jsp ">
4.    <textarea name= "t1 "> </textarea>
5.    <input type = "submit" name = "Submit" value ="Submit ">
6.</form>
7.</body>
8.</html>

2、test.jsp
Java代码
文本格式复制代码打印?
 

复制代码 代码示例:
1.<%@   page   contentType = "text/html;   charset=GB2312 "   language= "java "   %>
2.<%@   page   import= "java.util.*,java.text.* "%>
3.<%@   page   import= "java.io.* "%>
4.<html>
5.<head>
6.<title> Deal it </title>
7.<meta http-equiv = "Content-Type" content = "text/html;charset=gb2312 ">
8.</HEAD>
9.<BODY>
10.<%
11.        String content=request.getParameter( "t1 ");
12.if(content==null || content.equals( " "))
13.      return;
14.SimpleDateFormat sdf=new SimpleDateFormat( "yyyyMMdd ");
15.java.util.Date rightNow = new java.util.Date();
16.String tmp=sdf.format(rightNow);
17.System.out.println(tmp);
18.String filename=request.getRealPath( "/ ")+tmp+ ".html ";
19.System.out.println(filename);
20.try {
21.            File theFile=new File(filename);
22.            if (theFile.exists() == true)   {
23.                theFile.delete();
24.            }
25.            theFile.createNewFile();
26.            RandomAccessFile fout = new RandomAccessFile(filename, "rw ");
27.    content= " <html> <body> "+content+ " </body> </html> ";
28.            fout.writeBytes(content);
29.            fout.close();
30.        }catch(Exception e) {
31.            e.printStackTrace();
32.        }
33.System.out.println( "All is Over ");
34.%>
35.
36.</BODY>
37.</HTML>