Sana Ali

Greenhorn
+ Follow
since Oct 08, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sana Ali

Hi
I am trying to load data from an xml file in a form edit that info and update the xml file.

Currently I am able to view some information in the form.

But when I try and save (plus go to another page to perform save and display function) i have the following code:

/* Start of serialization code */

File myFile = new File(fileName);

//write the XML out into a file on the filesystem of the web server
FileWriter writer = new FileWriter(myFile, false);

//Create a new OutputFormat
OutputFormat format = new OutputFormat();
format.setIndenting(true);

//Create a new XMLSerializer that will be used to write out the XML
//Pass to it the writer object that defines where the output will
//be written to, and the format object that defines the format in
//which the XML will be generated
XMLSerializer serializer = new XMLSerializer(writer, format);

// Call the serialize() method, and pass to it out XML document
// stored in memory in a DOM tree
serializer.serialize(document);

/* End of serialization code */

The problem is instead of changing the values of the existing data, my code adds the new information to a new node to the xml tree.=\

Please Help.
Sana
[ October 21, 2004: Message edited by: Sana Ali ]
Thanks Pardeep...

i figured out the problem...

actually 1 of my integers was set to 999999 and then it was converted to string...

thats why this error was occuring.

Thanks again.
19 years ago
Hi, I have a form which takes input of memberID, LastName, FirstName.

Im using sessions and JavaBeans.

If memberID or LastName is not entered the user is to be prompted otherwise sent to the next form step.

parts of my code are:

<%@page import="java.io.*"%>
<%@page import="sana.member.MemberBean"%>

<jsp:useBean id="myMemberBean" class="sana.member.MemberBean" scope="session" />

<% myMemberBean.clear(); %>
<%!
//Define constants to represent states
public static final int DATA_ENTRY = 1;
public static final int MISSING_DATA = 2;
public static final int PROCEED_LOGIN = 3;

//Keep track of current state
int current_state;

String action = "",
id = "",
lastname = "",
firstname = "",
dateofbirth = "";
%>

<% action = request.getParameter("action");
id = request.getParameter("memberid");
lastname = request.getParameter("lastName");
firstname = request.getParameter("firstName");
dateofbirth = request.getParameter("dateofbirth");

// Figure out current state of system, and next permissible action

current_state = DATA_ENTRY; //default state

if (action != null && action.equals("PROCEED"))
{
current_state = PROCEED_LOGIN;

if (id == null || id.equals("") ||
lastname == null || lastname.equals(""))
{
current_state = MISSING_DATA;
}
}
%>

<html>....

<head>...</head>

<body>
<%
if (current_state == DATA_ENTRY || current_state == MISSING_DATA) {
%>
<table width="700" border="0" cellpadding="4" cellspacing="0">
<tr>
<th> <b>Member Details Input Step 1. . .</b></th>
</tr>

<%
if (current_state == MISSING_DATA) {
%>
<tr>
<td bgcolor="#FFFF66">
<p><strong>Fields Member ID and Last Name are mandatory</strong></p>
</td>
</tr>
<% } %>

</table>
<form method="post" action="memberinput2.jsp">
<input type="hidden" name="action" value="PROCEED" />

//Other code

<td><input type="submit" name="submit1" value=" Proceed to Step 2 "></td>
</tr>
</table>
</form>

<% } else if(current_state == PROCEED_LOGIN) {
response.sendRedirect("action");
%>

<% } else {
// Unknown state - should not occuru
%>

<table width="500" border=0
cellpadding=4 cellspacing=0>
<tr>
<td bgcolor="lightblue"><font color="white" face="Arial"><b>A system error has occurred.</b></font></td>
</tr>
</table>

<% } %>
//Other code

</body></html>

However, instead of the page getting reloaded and prompting the user to enter the missing data, the user is sent to the next page. :'(
Does any1 have a clue here?
Please help.
Sana
19 years ago
JSP
error is:

type Exception report

message Internal Server Error

description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.

exception
javax.servlet.ServletException
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:471)


javax.servlet.ServletException
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:471)
at org.apache.jsp.memberdisplayWithDom$jsp._jspService(memberdisplayWithDom$jsp.java:542)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)


root cause

java.lang.OutOfMemoryError
19 years ago
Hi I am getting this error from a recently fully functional file.

Could it be due to my code?

Or is it a server side error?
19 years ago
but im told to set it to "/tmp/fileName.xml"

as TOMCAT server runs there, other wise the jsp file cannot be executed.

Anyway, my Q was about my java code...does it even make sense?
19 years ago
Hi I am using DOM to make an xml tree and writing it to a file. The code involves use of java.

I have declared the fileName of the file:

String fileName = "/tmp/memberFile";

to save it to the file i have done the following:

File membersXMLFile = new File(fileName);
FileWriter writer;

if (!(membersXMLFile.exists()))
{
writer = new FileWriter(membersXMLFile);
}
else //file does exist
{
writer = new FileWriter(membersXMLFile, true);
}


if file does not exist FileWriter writes to file. else if it does exist, file writer writes to the file by appended to the file.

However, i am still getting a TOMCAT Error. As this is java code. I am confused on what is wrong with my code.

Please Help
Sana
19 years ago
Hi I am using DOM to make an xml tree and writing it to a file.

I have declared the fileName:

String fileName = "/tmp/memberFile";

to save it to the file i have done the following:

File membersXMLFile = new File(fileName);
FileWriter writer;

if (!(membersXMLFile.exists()))
{
writer = new FileWriter(membersXMLFile);
}
else //file does exist
{
writer = new FileWriter(membersXMLFile, true);
}


if file does not exist FileWriter writes to file. else if it does exist, file writer writes to the file by appended to the file.

However, i am still getting a TOMCAT Error. As this is java code. I am confused on what is wrong with my code.

Please Help
Sana
[ October 15, 2004: Message edited by: Sana Ali ]
actually,
it shud be setAttribute.

Im unaware of how to set more than 1 attribute
sorry for the indenting:s...it just changed here:s
My schema can hold phone where phone can be land line phone/mobile. The phone can be from any country.

a few examples i got in the sample xml file were

<phone type="home">+61 2 9345 6789</phone>
<phone type="work">+61 2 9514 1803</phone>
<phone type="fax">+61 2 9514 1807</phone>
<phone type="mobile">+61 4 1234 5678</phone>

<phone type="home">+44 (0) 8701 608123</phone>

the regular expression i think is suitable is:

value="+[\d" "()-]*"

Also,
since i have more than one types, i.e home, work, fax, mobile

in my schema i am using xs:union so the results in xml file match the schema

[q]
<xs:attributeGroup name="phone.attributes">
<xs:attribute name="type">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="home"/>
<xs:enumeration value="work"/>
<xs:enumeration value="fax"/>
<xs:enumeration value="mobile"/>
<xs:enumeration value="other"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:attributeGroup>
<xs:simpleType name="type">
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs attern value="\(\d\)\s*\d\s*\d"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs attern value="\d\s*\d\s*\d"/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
[/q]
this seems a bit dodgy, does any 1 here have a clue?

would this mean the out put will be stored still in the fields, while we are moving back and forth the pages?
19 years ago
JSP
Hi I am making a DOM tree, which will be supported by multiple JSP documents. Thus allowing an xml file to be made.

I am aware of how to set up the attribute, as the following example demonstrates:

//Create an element for member
//Place the <member> element underneath the <members> element in the tree
Element memberElement = document.createElement("member");
memberElement.setAttribute("id", idNum);
rootElement.appendChild(memberElement);

How ever, if we have an <address> element and we want to have "types" : "home" "work" and "postal" how can we do that?

I think it can be done the following way:

Element addressElement = document.createElement("address");
memberElement.setType("home", "work", "postal" );
memberElement.appendChild(addressElement);

please tell me if my "setType" is correct or not. Ive researched fair bit but im unable to find a solution. If its incorrect what shud be done to set "types" of an element.

Thanks,
S Ali
hi,

I am using java beans. As well as sessions.

I want to have more than 1 form buttons in one of my jsp files. For example 2 submit types called: "Back to Step 1"(input1.jsp) and "Proceed to Step 3" (input3.jsp) in a filed called input2.jsp

I want these to be in the form such that when we click "Back to Step 1" (input1.jsp) we go back one step, however, the data in the input fields on the input1.jsp is still visible, so user can edit the data.

and when after editing fields on input1.jsp the "Proceed to Step 2" (input2.jsp) button is pressed , the input2.jsp page appears, with the data we had entered before going back to input1.jsp still visible, so user can proceed with the form.

Also, i was wondering how can we have more than 2 buttons in logic,
as when we declare a form we use method="post" and action="input3.jsp"
So it seems only 1 button is supported:s. which i dont want.

But if i use 2 different forms for the two buttons the data on input1.jsp will not be visible in the form on input1.jsp.

Please help. Sorry Im a bit confused here:s Hope I have make myself cleared.

Cheers,
SA
19 years ago
JSP