浙江大学宁波明州医院:求个JSP小程序,满意的多加100分,在线等
来源:百度文库 编辑:查人人中国名人网 时间:2024/05/04 05:32:25
我的QQ42296806,邮箱cxf42296806@163.com,越小越好,几KB最好~~~
JSP,如果是课件,最好做个《用户登陆》或者《留言本》。
网上也有很多免费下载源代码的网站:
http://www.csdn.net 网络开发者
http://www.onjava.com 教程不多
http://www.javaworld.com
http://www.javaworld.com.tw 台湾的网站哦,10万帖
http://forum.javaeye.com
http://www.javareserach.com
http://java.chinaitlab.com
实在找不到,可以到Google搜一下!
如果还是没有,那,我给你:w_binglong@yahoo.com.cn
楼主注意:
楼上那个可能对你来说不真是,用这个吧
jsp 计数程序 我自己写的
<%
BufferedReader inf = new BufferedReader(new FileReader("/path/to/counter.txt"));
int tmp = Integer.parseInt(inf.readLine());
int i=0;
try {
i = Integer.parseInt(request.getSession().getValue("tal").toString());
} catch (NullPointerException t) {i=0; }
if (i==0) {
tmp++;
PrintWriter outf = new PrintWriter(new BufferedWriter(new FileWriter("/path/to/counter.txt")));
outf.println(tmp);
outf.close();
inf.close();
request.getSession().putValue("tal", "1");
}
BufferedReader inf2 = new BufferedReader(new FileReader("/path/to/counter.txt"));
%>
<%
String zeroes="";
String hits = inf2.readLine();
inf2.close();
for (int t=0; t < 8-hits.length(); t++) {
zeroes=zeroes+"0"; }
out.println(zeroes + hits);
%>
给你一个简单清晰而且有趣的例子给你呵呵,能反映出基本JSP的原理了~:
<%! static int a = 0;%>
<% static int b = 0;%>
<%=a++%> <%=b++%>
JSP中捕获 OUT 输出的例子
在CSDN里面看了一篇关于将动态JSP内容保存为静态页面的文章,忘记网址了,大家可以搜索一下 :)
他没有提供源代码,然后自己测试着写了一个.
主要想法是捕获 out 的输出后,可以保存到一些静态文件中,可以写一个 JSP的缓冲程序.
代码有待完善, 希望有这方面经验的朋友来共同完善.
在RESIN环境中测试成功,没有在tomcat其他服务器下测试,还存在一个问题,就是不能够同时输出到IE浏览器中.
?
以下为程序代码, 例如保存到 test.jsp 文件中,然后在IE中执行
http://....../test.jsp
将看不到任何输出,但是可以在后台resin的DOS窗口中看到输出的内容
<%@ page language="java" contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%!
//继承 JspWriter 类
class MyOut extends JspWriter
{
private HttpServletResponse response;
//将输出语句都存入os中
public CharArrayWriter os;
public MyOut()
{
super(0, false);
os = new CharArrayWriter();
}
public String getString() {
return os.toString();
}
public final void write(byte buf[], int off, int len)
throws IOException
{
os.write( new String(buf, off, len) );
}
public final void write(char buf[], int off, int len)
throws IOException
{
os.write( new String(buf, off, len) );
}
public final void write(int ch)
throws IOException
{
os.write( String.valueOf(ch) );
}
public final void write(char buf[])
throws IOException
{
os.write( String.valueOf(buf) );
}
public final void write(String s)
throws IOException
{
os.write( s );
}
public final void write(String s, int off, int len)
throws IOException
{
os.write( s, off, len );
}
public final void newLine()
throws IOException
{
os.write( "\n\r" );
}
public final void print(boolean b)
throws IOException
{
os.write( String.valueOf(b) );
}
public final void print(char ch)
throws IOException
{
os.write( String.valueOf(ch) );
}
public final void print(int i)
throws IOException
{
os.write( String.valueOf(i) );
}
public final void print(long l)
throws IOException
{
os.write( String.valueOf(l) );
}
public final void print(float f)
throws IOException
{
os.write( String.valueOf(f) );
}
public final void print(double d)
throws IOException
{
os.write( String.valueOf(d) );
}
public final void print(char s[])
throws IOException
{
os.write( String.valueOf(s) );
}
public final void print(String s)
throws IOException
{
os.write( s );
}
public final void print(Object o)
throws IOException
{
os.write( String.valueOf(o) );
}
public final void println()
throws IOException
{
os.write( "\n\r" );
}
public final void println(boolean b)
throws IOException
{
os.write( String.valueOf(b) );
}
public final void println(char ch)
throws IOException
{
os.write( String.valueOf(ch) );
}
public final void println(int i)
throws IOException
{
os.write( String.valueOf(i) );
}
public final void println(long l)
throws IOException
{
os.write( String.valueOf(l) );
}
public final void println(float f)
throws IOException
{
os.write( String.valueOf(f) );
}
public final void println(double d)
throws IOException
{
os.write( String.valueOf(d) );
}
public final void println(char s[])
throws IOException
{
os.write(s, 0, s.length);
}
public final void println(String s)
throws IOException
{
os.write(s);
}
public final void println(Object o)
throws IOException
{
os.write( String.valueOf(o) );
}
public final void clear()
throws IOException
{
os.reset();
}
public final void flush()
throws IOException
{
os.flush();
}
public void clearBuffer() {
os.reset();
}
public ServletOutputStream getOutputStream()
throws java.io.IOException
{
return response.getOutputStream();
}
//执行该方法可以将内容输出,或者保存为文件
public final void close()
throws IOException
{
System.out.println( "以下为静态输出" );
System.out.println( os.toString() );
}
public final int getBufferSize()
{
if(bufferSize == 0)
return bufferSize;
else
return response.getBufferSize();
}
public final int getRemaining()
{
return os.size();
}
public final boolean isAutoFlush()
{
return autoFlush;
}
}
%>
<%
out = new MyOut();
out.println( "开始输出, 在浏览器将会什么都不到<BR>" );
%>
<html>
<head>
<body>
<%
out.println( "文件内容" );
%>
</body>
</head>
</html>
<%
out.close();
%>