<%@ page contentType= "text/html; charset=GBK " %>
<%@ page import= "java.io.* " language= "java " %>
<%!
public String codeToString(String str)
{
String s=str;
try
{
Byte [] bytearray=s.getBytes( "ISO-8859-1 ");
str=new String(bytearray);
return str;
}
catch(Exception ce)
{
return str;
}
}
%>
<script language= "javascript " type= " ">
function on_submit()
{
if(form1.story_content.value== " ")
{
alert( "故事内容不能为空,请重新输入! ");
form1.story_content.value.focus();
return false;
}
}
</script>
<%//把提交的故事内容写入文件
int RowSize=30;
String tempString1=null;
String tempString2=null;
tempString1=codeToString(request.getParameter( "story_content "));
if(tempString!=null)
{
File tempFile1=new File( "d:/story.txt ");
FileWriter outfile1=new FileWriter(tempFile1);
BufferedWrite outbuffer1=new BufferedInputStream(outfile1);
int writeStringLength=tempString1.length();
for(int i=0;i <writeStringLength/rowSize+1;i++)
{
if((i+1)*rowSize <writeStringLength)
{
tempString2=tempString1.substring(i*RowSize,(i+1)*RowSize);
}
else
{
tempString2=tempString11.substring(i*Rowsize,(i+1)*RowSize);
}
}
outbuffer1.write(tempString2);
outbuffer1.newLine();
}
outbuffer1.flush();
outbuffer1.close();
outfile1.close();
}
%>
<html>
<head>
</head>
<body>
<div align= "center ">
<center>
<table border= "1 ">
<tr> <td colspan= "2 " align= "center "> 故事接龙游戏 </td>
</tr>
<tr>
<td> 游戏规则 </td>
<td> 在后面的文本框中续写故事,一次写一段,写完后提交。 </td>