J
Jenny
Hi,
I have a html file and JSP file. The JSP file opens a c:\hi.txt file
and write a string into it. But when I click the submit button on the
html file to run the JSP file, it does not create the file. (The code
worked in a Java application, so there are no errors). Could you tell
me why it did not create the file with JSP? I am using tomcat 4 and
windows 2000 server on my PC.
Thanks a lot.
Below is html code:
<HTML>
<HEAD><TITLE>Credit Card Information Form</TITLE></HEAD>
<BODY>
<FORM ACTION="creditCardForm.jsp" METHOD="POST">
Credit Card Information
<P> Name: <INPUT TYPE="TEXT" NAME="name" SIZE="25">
<P> Credit Card Number: <INPUT TYPE="TEXT" NAME="number" SIZE="25">
<P> Credit Card Type:
<SELECT NAME="type">
<OPTION>Visa</OPTION>
<OPTION>Master Card</OPTION>
<OPTION SELECTED>Amex</OPTION>
</SELECT>
<P> Expiration Date:
<SELECT NAME="month">
<OPTION SELECTED>01</OPTION> <OPTION>02</OPTION>
<OPTION>03</OPTION> <OPTION>04</OPTION>
<OPTION>05</OPTION> <OPTION>06</OPTION>
<OPTION>07</OPTION> <OPTION>08</OPTION>
<OPTION>09</OPTION> <OPTION>10</OPTION>
<OPTION>11</OPTION> <OPTION>12</OPTION>
</SELECT>
<SELECT NAME="year">
<OPTION>2000</OPTION> <OPTION SELECTED>2001</OPTION>
<OPTION>2002</OPTION> <OPTION>2003</OPTION>
<OPTION>2004</OPTION> <OPTION>2005</OPTION>
</SELECT>
<P>
<INPUT TYPE="RESET" NAME="Reset" VALUE="Reset">
<INPUT TYPE="SUBMIT" NAME="Submit" VALUE="Submit"></TD>
</FORM>
</BODY>
Below is JSP file:
<HTML><HEAD> <TITLE>Credit Card Processing JSP</TITLE>
</HEAD>
<BODY>
Verify Credit Card Information:
<%@ page import="java.io.*"%>
<%
try {
File f = new File("c://hell.txt");
FileOutputStream file = new FileOutputStream(f);
byte[] b = new byte[40];
b="Hello World.".getBytes();
file.write(b);
file.close();
} catch (Exception e) {
System.out.println("Error: " + e.toString());
}
%>
<UL>
<LI>Name = <%= request.getParameter("name") %>
<LI>Number = <%= request.getParameter("number") %>
<LI>Type = <%= request.getParameter("type") %>
<LI>Date = <%= request.getParameter("month") %>/
<%= request.getParameter("year")%>
</UL>
</BODY></HTML>
I have a html file and JSP file. The JSP file opens a c:\hi.txt file
and write a string into it. But when I click the submit button on the
html file to run the JSP file, it does not create the file. (The code
worked in a Java application, so there are no errors). Could you tell
me why it did not create the file with JSP? I am using tomcat 4 and
windows 2000 server on my PC.
Thanks a lot.
Below is html code:
<HTML>
<HEAD><TITLE>Credit Card Information Form</TITLE></HEAD>
<BODY>
<FORM ACTION="creditCardForm.jsp" METHOD="POST">
Credit Card Information
<P> Name: <INPUT TYPE="TEXT" NAME="name" SIZE="25">
<P> Credit Card Number: <INPUT TYPE="TEXT" NAME="number" SIZE="25">
<P> Credit Card Type:
<SELECT NAME="type">
<OPTION>Visa</OPTION>
<OPTION>Master Card</OPTION>
<OPTION SELECTED>Amex</OPTION>
</SELECT>
<P> Expiration Date:
<SELECT NAME="month">
<OPTION SELECTED>01</OPTION> <OPTION>02</OPTION>
<OPTION>03</OPTION> <OPTION>04</OPTION>
<OPTION>05</OPTION> <OPTION>06</OPTION>
<OPTION>07</OPTION> <OPTION>08</OPTION>
<OPTION>09</OPTION> <OPTION>10</OPTION>
<OPTION>11</OPTION> <OPTION>12</OPTION>
</SELECT>
<SELECT NAME="year">
<OPTION>2000</OPTION> <OPTION SELECTED>2001</OPTION>
<OPTION>2002</OPTION> <OPTION>2003</OPTION>
<OPTION>2004</OPTION> <OPTION>2005</OPTION>
</SELECT>
<P>
<INPUT TYPE="RESET" NAME="Reset" VALUE="Reset">
<INPUT TYPE="SUBMIT" NAME="Submit" VALUE="Submit"></TD>
</FORM>
</BODY>
Below is JSP file:
<HTML><HEAD> <TITLE>Credit Card Processing JSP</TITLE>
</HEAD>
<BODY>
Verify Credit Card Information:
<%@ page import="java.io.*"%>
<%
try {
File f = new File("c://hell.txt");
FileOutputStream file = new FileOutputStream(f);
byte[] b = new byte[40];
b="Hello World.".getBytes();
file.write(b);
file.close();
} catch (Exception e) {
System.out.println("Error: " + e.toString());
}
%>
<UL>
<LI>Name = <%= request.getParameter("name") %>
<LI>Number = <%= request.getParameter("number") %>
<LI>Type = <%= request.getParameter("type") %>
<LI>Date = <%= request.getParameter("month") %>/
<%= request.getParameter("year")%>
</UL>
</BODY></HTML>