您的位置:首页 > Web前端 > HTML

提交表单生成html文件的方法

2012-01-11 15:09 295 查看
1、test.html

Java代码

文本格式复制代码打印?

<html>

<body>

<form name = "form1" method = "post" action = "test.jsp ">

<textarea name= "t1 "> </textarea>

<input type = "submit" name = "Submit" value ="Submit ">

</form>

</body>

</html>

2、test.jsp

Java代码

文本格式复制代码打印?

<%@ page contentType = "text/html; charset=GB2312 " language= "java " %>

<%@ page import= "java.util.*,java.text.* "%>

<%@ page import= "java.io.* "%>

<html>

<head>

<title> Deal it </title>

<meta http-equiv = "Content-Type" content = "text/html;charset=gb2312 ">

</HEAD>

<BODY>

<%

String content=request.getParameter( "t1 ");

if(content==null || content.equals( " "))

return;

SimpleDateFormat sdf=new SimpleDateFormat( "yyyyMMdd ");

java.util.Date rightNow = new java.util.Date();

String tmp=sdf.format(rightNow);

System.out.println(tmp);

String filename=request.getRealPath( "/ ")+tmp+ ".html ";

System.out.println(filename);

try {

File theFile=new File(filename);

if (theFile.exists() == true) {

theFile.delete();

}

theFile.createNewFile();

RandomAccessFile fout = new RandomAccessFile(filename, "rw ");

content= " <html> <body> "+content+ " </body> </html> ";

fout.writeBytes(content);

fout.close();

}catch(Exception e) {

e.printStackTrace();

}

System.out.println( "All is Over ");

%>

</BODY>

</HTML>

本文转载自 http://www.itjianghu.net/120108/40916358935185219.htm
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Java 职场 html