problem aligning text file into browser
843835Jun 20 2002 — edited Jun 21 2002i can upload the file (txt file) and read the file using servlet. the problem now is alignment. Someone sugguested me using StringTokenize but then i still cannot align nicely in browser..can someone help mi??
servlet codes:
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.oreilly.servlet.MultipartRequest;
import java.util.StringTokenizer;
public class UploadServlet extends HttpServlet
{ public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
try{
//Construct a MultipartRequest to help read the information
//Pass in request, a direectory to save files to, and the
//maximum POST size we should attempt to handle
//Write to the server root and impose 5 meg limit
MultipartRequest multi = new MultipartRequest(req, ".", 5*1024*1024);
Enumeration files=multi.getFileNames();
String name=(String)files.nextElement();
String filename = multi.getFilesystemName(name);
String type=multi.getContentType(name);
File f=multi.getFile(name);
FileInputStream fis=new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream dis=new DataInputStream(bis);
String str;
while((str = dis.readLine())!=null)
{ str = dis.readLine();
StringTokenizer st = new StringTokenizer(str, " ,\t\r\n");
while (st.hasMoreTokens())
{
String token = st.nextToken();
out.println(token);
}
int k=0;
int comma=0;
int len;
int i = 0;
String value="";
String values[] = new String[30];
if(str.charAt(i)==',')
{
if(str.substring(comma,i).equals(""))
{
value="null";
}
else
{
value=str.substring(comma,i);
}
comma=i+1;
values[k]=value;
out.println("value of "+k+" is "+values[k]);
k=k+1;
}
}
}
catch(Exception e)
{
e.printStackTrace(out);
}
}
}
jsp codes:
<html>
<head>
<!-- header - edit "Data/yourHtmlHeader" to customize -->
<!-- contents - edit "EventHandlers/Html file/onCreate" to customize -->
<meta name="generator" content="ModelWorks IDE">
<title>MIcroarry Visualisation</title>
</head>
<body background="bkgrd_proj1 .jpg">
<pre>
<H1> Microarray Visualisation </H1>
<FORM action=/servlet/UploadServlet enctype="multipart/form-data" method=post>
Select the files you want to upload:<P>
File: <INPUT type="file" name="file"><BR>
<INPUT TYPE="submit" VALUE="Upload">
</FORM>
</pre>
</body>
</html>