JSP小应用

xuancao 2003-08-01 09:10:00
<%@ page language="java" %>
<%@ page import="java.sql.*;java.io.*" %>
<script>
//返回字符串的字节长度
function getLen(str){
var i=0;
var result=0;
if(str==null) return strLen;
result=str.length;
for(i=0;i<str.length;i++){
if(str.charCodeAt(i)>255) {
result=result+1;
}
}
return result;
}
//有效性校验;
function check(){
var count = "<%= strCount %>";
if (count.indexOf("5")){
alert("非常抱歉,您已经输入5条数据,不能再输入,谢谢!");
return false;
}
form1 = document.form;
if (form1.chapter.value=="" || form1.chapter.value==" "){
alert("非常抱歉,输入章不能为空,请重新输入!");
form1.chapter.select();
return false;
}
if (form1.section.value=="" || form1.section.value==" "){
alert("非常抱歉,输入节不能为空,请重新输入!");
form1.section.select();
return false;
}
if (form1.content.value=="" || form1.content.value==" "){
alert("非常抱歉,输入内容不能为空,请重新输入!");
form1.content.select();
return false;
}
if ( getLenB(form1.content)>4000){
alert("非常抱歉,输入内容太多,请重新输入!");
form1.content.select();
return false;
}
form1.submit();
}

</script>
<%
//获取参数,判断是否提交数据标志,如果strFlag等于"true",则提交新增,否则,显示新增页面;
String strFlag = request.getParameter("strFlag");
if (strFlag !=null && strFlag.equals("true"){
String strChapter = request.getParameter("chapter");
String strSection = request.getParameter("section");
String strContent = request.getParameter("content");

//保存内容到文件,文件名为时间序号+txt
java.util.Date date = new java.util.Date();
String strPath = "c:\\" + date.toString(); + ".txt";
OutputStream bos = new FileOutputStream(strPath);
bos.write(strContent.getBytes());
bos.close();

//保存内容到数据库:数据库-base;表-table,字段-chapter,section,url;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String strUrl = "";
Connection con=DriverManager.getConnection("jdbc:odbc:base","user","passward");
Statment stmt = con.createStatement();
String strSql = " insert into table (chapter,section,url) values('"
+ strChapter + "','" + strSection + "','" + strPath + "')" ;
stmt.executeUpdate(strSql);

//获取已经存在的数据记录
ResultSet rsCount = stmt.executeQuery("select count(*) from table");
rsCount.next();
String strCount = rsCount.getString(1);

if (rs !=null) rs.close();
if (stmt!=null) stmt.close();
if (con !=null) con.close();

}
%>
<form name="form1" method="post" action="index.jsp">
<font color="#FF0000"> 二、自定义培训内容 </font>       
<p>               </p>
<p>           
<input type="text" name="chapter">
章 </p>
<p>           
<input type="text" name="section">
节</p>
<p>  </p>
<p>          
<textarea name="content" cols="" rows="20" >内容不超过四千字

</textarea>
<input type="hidden" name="strFlag" value="true"/>
<input type="button" name="Submit" value="完成" onclick="check()">
</p>
<p>{允许自定义五个}</p>
<p>//实现用户进入叶面后!输入章名!节名!内容!点完成后!</p>
<p>//章名节名分别存入数据库字段</p>
<p>//内容写入一个xxx.txt文件!这个txt文件的路径写入数据库字段以便</p>
<p>//其它叶面通过读入路径读出文件内容</p>
<p>//只允许自定义五个培训内容</p>
<p> </p>
<p>  </p>
</form>
...全文
188 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuancao 2003-08-04
  • 打赏
  • 举报
回复
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%
String strCount = "0";
//»ñÈ¡²ÎÊý,ÅжÏÊÇ·ñÌá½»Êý¾Ý±êÖ¾,Èç¹ûstrFlagµÈÓÚ"true",ÔòÌá½»ÐÂÔö,·ñÔò,ÏÔʾÐÂÔöÒ³Ãæ;
String strFlag = request.getParameter("strFlag");
if (strFlag !=null && strFlag.equals("true")){
String strChapter = request.getParameter("chapter");
String strSection = request.getParameter("section");
String strContent = request.getParameter("content");

//±£´æÄÚÈݵ½Îļþ,ÎļþÃûΪʱ¼äÐòºÅ+txt
java.util.Date date = new java.util.Date();
String strPath = "c:\\" + date.toString() + ".txt";
OutputStream bos = new FileOutputStream(strPath);
bos.write(strContent.getBytes());
bos.close();

//±£´æÄÚÈݵ½Êý¾Ý¿â:Êý¾Ý¿â-base;±í-table,×Ö¶Î-chapter,section,url;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String strUrl = "";
Connection con=DriverManager.getConnection("jdbc:odbc:base","user","passward");
Statement stmt = con.createStatement();
String strSql = " insert into table (chapter,section,url) values('"
+ strChapter + "','" + strSection + "','" + strPath + "')" ;
stmt.executeUpdate(strSql);

//»ñÈ¡ÒѾ­´æÔÚµÄÊý¾Ý¼Ç¼
ResultSet rsCount = stmt.executeQuery("select count(*) from table");
rsCount.next();
strCount = rsCount.getString(1);

if (rsCount !=null) rsCount.close();
if (stmt!=null) stmt.close();
if (con !=null) con.close();

}
%>
<script>
//·µ»Ø×Ö·û´®µÄ×Ö½Ú³¤¶È
function getLen(str){
var i=0;
var result=0;
if(str==null) return strLen;
result=str.length;
for(i=0;i<str.length;i++){
if(str.charCodeAt(i)>255) {
result=result+1;
}
}
return result;
}
//ÓÐЧÐÔУÑé;
function check(){
var count = "<%= strCount %>";
if (count.indexOf("5")){
alert("·Ç³£±§Ç¸,ÄúÒѾ­ÊäÈë5ÌõÊý¾Ý,²»ÄÜÔÙÊäÈë,лл!");
return false;
}
form1 = document.form;
if (form1.chapter.value=="" || form1.chapter.value==" "){
alert("·Ç³£±§Ç¸,ÊäÈëÕ²»ÄÜΪ¿Õ,ÇëÖØÐÂÊäÈë!");
form1.chapter.select();
return false;
}
if (form1.section.value=="" || form1.section.value==" "){
alert("·Ç³£±§Ç¸,ÊäÈë½Ú²»ÄÜΪ¿Õ,ÇëÖØÐÂÊäÈë!");
form1.section.select();
return false;
}
if (form1.content.value=="" || form1.content.value==" "){
alert("·Ç³£±§Ç¸,ÊäÈëÄÚÈݲ»ÄÜΪ¿Õ,ÇëÖØÐÂÊäÈë!");
form1.content.select();
return false;
}
if ( getLenB(form1.content)>4000){
alert("·Ç³£±§Ç¸,ÊäÈëÄÚÈÝÌ«¶à,ÇëÖØÐÂÊäÈë!");
form1.content.select();
return false;
}
form1.submit();
}

</script>

<form name="form1" method="post" action="index.jsp">
<font color="#FF0000"> ¶þ¡¢×Ô¶¨ÒåÅàѵÄÚÈÝ¡¡</font>¡¡¡¡¡¡¡¡¡¡¡¡¡¡
<p>¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ¡¡¡¡ </p>
<p> ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
<input type="text" name="chapter">
ÕÂ </p>
<p> ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
<input type="text" name="section">
½Ú</p>
<p>  </p>
<p>¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
<textarea name="content" cols="" rows="20" >ÄÚÈݲ»³¬¹ýËÄǧ×Ö

</textarea>
<input type="hidden" name="strFlag" value="true"/>
<input type="button" name="Submit" value="Íê³É" onclick="check()">
</p>
<p>£ûÔÊÐí×Ô¶¨ÒåÎå¸ö£ý</p>
<p>//ʵÏÖÓû§½øÈëÒ¶Ãæºó£¡ÊäÈëÕÂÃû£¡½ÚÃû£¡ÄÚÈÝ£¡µãÍê³Éºó£¡</p>
<p>//ÕÂÃû½ÚÃû·Ö±ð´æÈëÊý¾Ý¿â×Ö¶Î</p>
<p>//ÄÚÈÝдÈëÒ»¸öxxx.txtÎļþ£¡Õâ¸ötxtÎļþµÄ·¾¶Ð´ÈëÊý¾Ý¿â×Ö¶ÎÒÔ±ã</p>
<p>//ÆäËüÒ¶Ãæͨ¹ý¶ÁÈë·¾¶¶Á³öÎļþÄÚÈÝ</p>
<p>//Ö»ÔÊÐí×Ô¶¨ÒåÎå¸öÅàѵÄÚÈÝ</p>
<p> </p>
<p>  </p>
</form>
nilr 2003-08-02
  • 打赏
  • 举报
回复
是什么东西啊.哈哈.
Hodex 2003-08-01
  • 打赏
  • 举报
回复
呵呵,有些书上还有一些其它的函数,也帖出来啥
xdev 2003-08-01
  • 打赏
  • 举报
回复
o , 不知道什么用
luckyfanjian 2003-08-01
  • 打赏
  • 举报
回复
很好!

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧