Java Server Pages
掲示板のサンプル・ソース
<%@page
contentType="text/html; charset=x-euc-jp"
import="java.io.*"
import="java.util.*"
errorPage='errorpage.jsp'
isErrorPage="true"
%>
<%
// 11 jan 04
String ecgi = "notice.jsp";
String rgroup = request.getParameter("group");
String topad = "";
if (rgroup == null || rgroup.equals("")){
topad = "/index.html";
rgroup = "";
}else{
topad = "/" + rgroup + "/index.html";
}
String rpage = request.getParameter("page");
if (rpage == null || rpage.equals("")){
rpage = "0";
}
int pagei = Integer.parseInt(rpage);
if (pagei < 0){ pagei = 0; }
int front = pagei - 5;
int rear = pagei + 5;
String rclass = request.getParameter("class");
if (rclass == null || rclass.equals("")){
rclass = "var";
}
String rword = request.getParameter("word");
if (rword == null || rword.equals("")){
rword = "";
}
// 19 jan 04
String fipas = "/home/httpd/html/cgi-bin/bbs/firstplace.log";
String fidata = "";
String kurasu = "";
String title = "";
String hozonkensu = "";
String gazosaizu = "";
String chakushin = "";
String mailto = "";
String modoruurl = "";
String riyosha = "";
FileInputStream fiinStream = new FileInputStream(fipas);
InputStreamReader fiinFile = new InputStreamReader(fiinStream, "Shift_JIS");
BufferedReader fibuff = new BufferedReader(fiinFile);
while ((fidata = fibuff.readLine()) != null){
if (fidata.indexOf(rclass) == 0){
kurasu = fidata.substring(0,fidata.indexOf(","));
fidata = fidata.substring(fidata.indexOf(",")+1);
title = fidata.substring(0,fidata.indexOf(","));
fidata = fidata.substring(fidata.indexOf(",")+1);
hozonkensu = fidata.substring(0,fidata.indexOf(","));
fidata = fidata.substring(fidata.indexOf(",")+1);
gazosaizu = fidata.substring(0,fidata.indexOf(","));
fidata = fidata.substring(fidata.indexOf(",")+1);
chakushin = fidata.substring(0,fidata.indexOf(","));
fidata = fidata.substring(fidata.indexOf(",")+1);
mailto = fidata.substring(0,fidata.indexOf(","));
fidata = fidata.substring(fidata.indexOf(",")+1);
modoruurl = fidata.substring(0,fidata.indexOf(","));
riyosha = fidata.substring(fidata.indexOf(",")+1);
}
}
fiinFile.close();
String rfipas = "/home/httpd/html/cgi-bin/bbs/" + rclass + "r.log";
String rfidata = "";
FileInputStream rfiinStream = new FileInputStream(rfipas);
InputStreamReader rfiinFile = new InputStreamReader(rfiinStream, "Shift_JIS");
BufferedReader rfibuff = new BufferedReader(rfiinFile);
rfidata = rfibuff.readLine();
rfiinFile.close();
int rpagei = Integer.parseInt(rfidata);
// 11 jan 04
String hyoji = "";
String arika = "/home/httpd/html/cgi-bin/" + rclass;
File nfile = new File(arika);
String flist[] = nfile.list();
Arrays.sort(flist);
int flen = flist.length;
String second[] = new String[flen];
int toros = 0;
for(int i=0; i<flen; i++){
if (flist[i].indexOf(".") < 0){
//hyoji = hyoji + "<BR>" + flist[i];
second[toros] = flist[i];
toros++;
}
}
// 19 jan 04
String third[] = new String[flen];
String forth[] = new String[flen];
int ti = 0;
int fi = 0;
for (int j=0; j<toros; j++){
if (Integer.parseInt(second[j])<rpagei){
third[ti] = second[j];
ti++;
}else{
forth[fi] = second[j];
fi++;
}
}
int si = 0;
for (int l=0; l<fi; l++){
second[si] = forth[l];
si++;
}
for (int k=0; k<ti; k++){
second[si] = third[k];
si++;
}
// 11 jan 04
int maxp = 0;
int minp = toros;
int spage = 4;
if(toros > 5){
maxp = toros - 5 - pagei;
minp = toros - pagei;
}else{
maxp = 0;
spage = toros - 1;
}
String hpage[] = new String[5];
for(int i=0; i<toros; i++){
if (i >= minp){ break; }
if(i >= maxp){
hpage[i-maxp] = second[i];
// hyoji = hyoji + "<BR>" + hpage[i-maxp];
}
}
int q = 0;
for(int i=spage; i>=0; i--){
String adate = "";
String afrom = "";
String asubject = "";
String acolor = "";
String apicture = "";
String amessage = "";
String data = "";
String filname = arika + "/" + hpage[i];
FileInputStream inStream = new FileInputStream(filname);
InputStreamReader inFile = new InputStreamReader(inStream, "Shift_JIS");
BufferedReader buff = new BufferedReader(inFile);
while ((data = buff.readLine()) != null){
if (data.indexOf("Date:") == 0){
adate = data.substring(6);
}else if(data.indexOf("From:") == 0){
afrom = data.substring(6);
}else if(data.indexOf("Subject:") == 0){
asubject = data.substring(9);
}else if(data.indexOf("Color:") == 0){
acolor = data.substring(7);
}else if(data.indexOf("Picture:") == 0){
apicture = data.substring(9);
}else{
amessage = amessage + data + "<BR>" + "\n";
}
// hyoji = hyoji + data + "<BR>" + "\n";
}
inFile.close();
int n = afrom.indexOf("<");
if(n > 0){
afrom = afrom.substring(0,n);
}
String fcolor = "#000000";
String bcolor = "#FFFFFF";
int p = acolor.indexOf(":");
if(p > 0){
bcolor = acolor.substring(0,p);
fcolor = acolor.substring(p+1);
}
String tichi = "";
if (q == 0){
q = 1;
tichi = "ALIGN=left";
}else{
q = 0;
tichi = "ALIGN=right";
}
hyoji = hyoji + "<TABLE BORDER=4 CELLSPACING=4 " + tichi + ">\n<TR><TD BGCOLOR=\""+ bcolor + "\"><B>" + hpage[i] + " ";
hyoji = hyoji + asubject + "</B><BR>" + "\n";
hyoji = hyoji + "<I>" + adate + "</I><BR>" + "\n";
hyoji = hyoji + afrom + "<BR>" + "\n";
// gazosaizu = "10";
int pclen = 0;
int gazo = 0;
if (apicture.length() != 0 ){
apicture = apicture.substring(5);
String parika = "/home/httpd/html" + apicture;
File pfile = new File(parika);
long plen = pfile.length();
Long pilen = new Long(plen);
pclen = pilen.intValue();
gazo = Integer.parseInt(gazosaizu)*1000;
}
if (pclen < gazo && apicture.length() != 0){
hyoji = hyoji + "<BR><img src=\"" + apicture + "\"><BR>" + "\n";
}
hyoji = hyoji + "<FONT color=\"" + fcolor + "\">" + amessage + "</FONT>" + "\n";
if (pclen >= gazo && apicture.length() != 0){
int fsizel = pclen / 1000;
hyoji = hyoji + "<P><A HREF=\"" + apicture + "\">画像 " + fsizel + " KB</A>";
}
hyoji = hyoji + "</TD></TR></TABLE><br Clear=All><BR>" + "\n";
}
String maep = "";
if (front >= 0){
maep = "<A HREF=\"" + ecgi + "?page=" + front + "&group=" + rgroup + "&class=" + rclass + "\">前ページ</A> ";
}
String tsugip = "";
if (toros > rear){
tsugip = "<A HREF=\"" + ecgi + "?page=" + rear + "&group=" + rgroup + "&class=" + rclass + "\">次ページ</A> ";
}
%>
<html>
<head>
<META NAME="ROBOTS" CONTENT="NONE">
<TITLE>A bulletin board. Any news?</TITLE>
</head>
<body>
<TABLE BORDER=0 CELLSPACING=0 WIDTH="100%">
<TR><TD>
<IMG SRC="/club/ANYNEWS.GIF" alt="どんなニュース?"></TD>
<TD ALIGN=Right>
<form action="question.jsp" method="get">
<INPUT TYPE="hidden" NAME="group" VALUE="<%=rgroup%>">
<INPUT TYPE="hidden" NAME="class" VALUE="<%=rclass%>">
<input type="text" name="word" VALUE="<%=rword%>" size="30">
<input type="submit" value="Question">
</form>
</TD></TR>
</TABLE>
<span STYLE=" font-size: 14pt ; font-weight: bold ; ">
掲示板:<%=title%>
</span>
<P>
<P ALIGN=Right>
<%=maep%>
<%=tsugip%>
<A HREF="board.jsp?group=<%=rgroup%>&class=<%=rclass%>">新規登録</A>
<A HREF="clean.jsp?group=<%=rgroup%>&class=<%=rclass%>">削除編集</A>
<A HREF="havealook.jsp?group=<%=rgroup%>&class=<%=rclass%>">タイトル</A>
<A HREF="<%=topad%>">トップページ</A>
</P>
<%=hyoji%>
<P ALIGN=Right>
<%=maep%>
<%=tsugip%>
<A HREF="board.jsp?group=<%=rgroup%>&class=<%=rclass%>">新規登録</A>
<A HREF="clean.jsp?group=<%=rgroup%>&class=<%=rclass%>">削除編集</A>
<A HREF="havealook.jsp?group=<%=rgroup%>&class=<%=rclass%>">タイトル</A>
<A HREF="<%=topad%>">トップページ</A>
</P>
</body>
</html>
January 19, 2004
|
The following clause.
|
ソフトウェア
|