Problem in setAttribute() method
Hi ,
I am setting two values using setAttribute() method of HttpSession as shown below
Vector v = new Vector();
setAttribute("a",v)
setAttribute("b",v)
Then i retrieve object "a" and do some modifications and set it back in session. The problem is that object "b" also gets modified.
I tried using two vectors v1 and v2 but it did not get resolved.
Any pointers wud be helpful. Also, i m using WSAD IDE.
Regards,
PAWAN
Then i retrieve object "a" and do some modifications and set it back in session.The session contains references to the objects. It doesn't contain the objects themselves. So when you retrieve object "a", you get a reference to an object. You then do some modifications. But you don't need to "put it back" into the session because the session already contains a reference to the object that you just modified.
And that is the root of your problem. Your session contains two references ("a" and "b") to the same object.
Similar Messages
-
Hi to all,
Iam building xml file.In that iam trying to create org.jdom.NameSpace in setAttribute() method of org.jdom.Element object. Iam getting runtime errors like illegal name.
What exactly i want is i want to set "xmlns" as attribute name and "http://www.loc.gov/MARC21/slim" as attribute value. When iam directly creating that it is throwing exception that no attribute name should be xmlns in org.jdom.Element. That is why i approched to org.jdom.NameSpace. But iam not getting the way, how to set org.jdom.NameSpace in setAttribute method of org.jdom.Element object. I tried several ways but it is not comming.
can any budy help me please.
thanks to one and all.Hi Marc
I solved the problem
Actually the oRootElement.toString was returning me only the string and not the
XML formatted String eg:
<?xml version="1.0" encoding="UTF-8"?>
<response id="2"><apartment id="1"/><clips><clip><id>1</id><timeStamp>2000000</timeStamp><size>100</size></clip><clip><id>2</id><timeStamp>4000000</timeStamp><size>200</size></clip></clips></response>
So the very first tag was missing <?xml version="1.0" encoding="UTF-8"?> when i used element.toString();
But now i used StreamResult and Transformer
which gives me the same XMl format as i want and it works fine with both
JRE1.4 and JRE1.5
Thank you
Geetanjalee -
I have problem with pay method
I have problem with pay method. My card declined. I change card and I have the same problem. What can i do? Why declined my card again?
Contact iTunes store support: https://ssl.apple.com/emea/support/itunes/contact.html.
-
Hi, I am having this problem:
I made a CustomItem, a TextField, now I overloaded the traverse method, so if the keycode is Canvas.UP or Canvas.DOWN then return false else return true.
The problem is that when I press the left or rigth button it also returns false and not true.
and there is another problem with traverse, before returning false or true I set a boolean and call to repaint to draw it on some way if its selected or not, the paint method is being called but it just dont draw as desired.
protected void paint(Graphics g, int ancho, int alto) {
System.out.println ("Dentro del paint, seleccionado="+seleccionado);
try {
g.drawString(label, 0, 0, Graphics.TOP|Graphics.LEFT);
if (!seleccionado) {
g.setColor(120, 120, 120);
g.drawRect(0, 4, tama�oTexto+8, 25);
if (seleccionado) {
g.setColor(255, 255, 255);
g.fillRect(1, 5, (tama�oTexto+8-1), 23);
g.setColor(0, 0, 0);
if (!seleccionado) {
g.setColor(80, 80, 80);
g.drawString(texto, 4, 7, Graphics.TOP|Graphics.LEFT);
if (seleccionado) {
int cursorX=Font.getDefaultFont().charsWidth((texto.substring(0, idLetraActual)).toCharArray(), 0, texto.substring(0, idLetraActual).length())+4;
g.drawChar('|', cursorX, 7, Graphics.TOP|Graphics.LEFT);
} catch (Exception E){
E.printStackTrace();
}the traverse method set the seleccionado variable and calls to repaint but instead of being false the paint method is drawing it as true (most of times).I have a problem with findByxxx() method.. in
Container managed bean.
i have
Collection collection =
home.findByOwnerName("fieldValue");
specified in my Client Program, where ownerName is the
cmp fieldname..
and
public Collection findByOwnerName(String ownerName)
throws RemoteException, FinderException
defined in my home interface.
i have not mentioned the findBy() method anywhere else
(Bean class). You have to describe the query in the deployment descriptor.
>
Even if i have a same "fieldValue" in the database
(Oracle), which i specified in findBy() method, iam a
result of owner Not found, which is not the case as i
have that owner name.
for the same application if i use findByPrimaryKey(),
it is working..
Can any one please post me the solution. -
Problem with Vector method addElement
I am new to Java. I am using JDK 1.3. I am writing a program that will convert a text file to a binary file that stores a Vector object. I have narrowed my problem to the method that reads the text file and creates my vector. Each element in my vector stores an integer and a string variable. The reading of the text file works find and the creation of my record works find. It seems that the storing of the record in the vector is not working. When I print the first 10 elements of the vector, it have the same record(the last record of my text file). What is wrong with the method below? I am also appending the result of running my program.
private static void readTextFile(File f) {
try {
FileReader fileIn = new FileReader(f);
BufferedReader in = new BufferedReader(fileIn);
String line;
int i;
SsnLocationRecord recordIn = new SsnLocationRecord();
int ctr = 0;
while (true) {
line = in.readLine();
if (line == null)
break;
ctr += 1;
i = line.indexOf(" ");
recordIn.putAreaNumber(Integer.parseInt(line.substring(0,i).trim()));
recordIn.putLocation(line.substring(i+1).trim());
records.addElement(recordIn);
if (ctr < 11)
System.out.println(recordIn);
in.close();
} catch (IOException e) {
System.out.println ("Error reading file");
System.exit(0);
for (int i = 0; i < 11; i++)
System.out.println((SsnLocationRecord) records.elementAt(i));
RESULTS:
C:\Training\Java>java ConvertTextFileToObjectFile data\ssn.dat
0 null
3 New Hampshire
7 Maine
9 Vermont
34 Massachusetts
39 Rhode Island
49 Connecticut
134 New York
158 New Jersey
211 Pennsylvania
680 Nevada
680 Nevada
680 Nevada
680 Nevada
680 Nevada
680 Nevada
680 Nevada
680 Nevada
680 Nevada
680 Nevada
680 Nevada
C:\Training\Java>First of all it would be better if you did a priming read and then checked line == null in the while statement instead of the way you have it.
ctr++ will also accomplish what ctr +=1 is doing.
you need to create a new instance of SsnLocationRecord for each line read. What you are doing is overlaying the objects data each time you execute the .putxxxx methods. The reference to the object is placed in the vector. The actual object is still being updated by the .putxxx methods (NOTE : THIS IS THE ANSWER TO YOUR MAIN QUESTION).
you close should be in a finally statement.
To process through all the elements of a Vector create an Enumeration and then use the nextElement() method instead of the elementAt is probably better. (Some will argue with me on this I am sure).
Also, on a catch do not call System.exit(0). This will end your JVM normally. Instead throw an Exception (Runtime or Error level if you want an abnormal end). -
Hi,
I have a problem with the method prerender. A month ago, I started to develop a web project using Sun Studio Creator and a few page beans that i used extended the Abstract Page Bean, so I overrided the prerender and customized it.
The problem is that, now i'm using eclipse and the configuration files of the project has changed and the prerender method never execute.
I want to know why it is happening. Maybe the project is "bad-configurated"?
ThanksThe code of java bean doesn't change, the only thing that has changed is the configuration files (faces-config.xml, web.xml, etc).
I put a breakpoint in the prerender method but the lifecycle doesn�t execute this method.
After serveral changes, I wrote this code in the method prerender :
int i=0;
i = 1;
And the prerender method doesn't execute.
I'm a bit lost,
thanks -
Problem with affinetransformOp method...
I have a serious problem with filter method
I Want to make a image flipping or some other filtering by using
AffineTransformOp
but it printouts an erro like this
cannot resolve symbol
op.filter (img, flipped)
(the error pointer shows ".after the op")
a code from my one of the filters
BufferedImage flipped = new BufferedImage(img.getHeight(), img.getWidth(),BufferedImage.TYPE_INT_RGB);
AffineTransform trans = new AffineTransform(0, 1, 1, 0, 0, 0);
AffineTransformOp op = new AffineTransformOp(trans, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
op.filter(img, flipped); //img is my buffered image source
I used some other ways like (img, null) but always give out error.
thanks..Did you declare "img" as BufferedImage or something else?
What is the full error message? -
Problem with WindowClosing() method
Hello everyone,
I have some problem with WindowClosing() method, in which I gave options
to quit or not. Quit is working fine but in case of Cancel, its not returning to
the frame. Can anyone help me ....Here is my code
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
import java.awt.event.*;
public class TestFrame extends JPanel
public static void main(String[] args)
JFrame frame = new JFrame("Frame3");
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
int button = JOptionPane.showConfirmDialog(null,"OK to Quit","",JOptionPane.YES_NO_OPTION, -1);
if(button == 0) {
System.exit(0);
else
return;
frame.addWindowListener(l);
frame.setSize(1200,950);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}Maybe try
int button = JOptionPane.showConfirmDialog(yourframe,"OK to
Quit","",JOptionPane.YES_NO_OPTION, -1); -
Problems using GET method in JSP
Hi,
I had some problems using GET method in JSP.
I'm using Apache web server 1.3 and Tomcat 3.3.1 in windows 2000.
And I'm using language English and Korean.
When I send messages using POST method, all is good
But when I send message using GET method, English is good, but Korean is not good.
I tried to encode using
URLEncode.encode(str, "UTF-8")
and decoding it using
URLDecode.decode(request.getParameter(tag), "UTF-8")
but it didn't work.
How can I receive request including Korean using GET method in JSP?
If anyone have solutions, please let me know.
thanks.Hi,
I had some problems using GET method in JSP.
I'm using Apache web server 1.3 and Tomcat 3.3.1 in
windows 2000.
And I'm using language English and Korean.
When I send messages using POST method, all is good
But when I send message using GET method, English is
good, but Korean is not good.
I tried to encode using
URLEncode.encode(str, "UTF-8")
and decoding it using
URLDecode.decode(request.getParameter(tag), "UTF-8")
but it didn't work.
How can I receive request including Korean using GET
method in JSP?
If anyone have solutions, please let me know.
thanks.This problem appears, when one use UTF-16 encoding in JSP - am I right?
If so there are two solutions:
1) Temporary: Use "UTF-8" - or any other 8 bit encoding scheme and
encode Korean symbols with "&1234;" kind of escapes - though it
may not work
2) Absolute: get my piece of code, which I have managed to write
just a month ago resolving absolutely similar problem with UTF-16
in code using Chinese/Russian/English encodings
But I wouldn't say that it's costs 10 DDs :) - it's much more
expensive... So try 1st variant if it wouldn't help - let me know.
I'll figure :)
Paul -
Screen Resolution Problem in Session Method
Hi
I want to use session method in BDC. How to resolve screen resolution problem in Session Method?
Please give me the code or steps regarding this.
Thanks & Regards
venkateswararaoHi
U can only run the session with the option Dynpro Standard Size setted.
In this way the system should be use the same resolution for every situation.
Max -
Problems w my method payment
Go to settings/itunes & app store tap on ID then view ID then tap payment information and see whether paypal is a payment option for you. If it is not then you will need to check from one of the available payment options
-
I have problem verifying payment method by my pre-paid visa credit card
I have a problem verifying payment method by my pre-paid visa credit card ???
Apple does not accept pre paid cards > iTunes Store: Accepted forms of payment
Purchase an iTunes gift card that you can redeem and use to purchase iTunes and App Store content.
http://www.apple.com/itunes/gifts/?cid=wwa-us-kwg-music-itu -
I am trying to install free apps but I always get billing problem? Payment Method!!?
Likely because you are trying to create a Mac App Store account with an existing Apple ID. The None option often is not available in that case. If you create a new Apple ID and iTunes/Mac App Store account following these instructions carefully, you will be successful in getting free apps without a payment method.
Creating an iTunes Store, App Store, iBookstore, and Mac App Store account without a credit card -
http://support.apple.com/kb/HT2534 -
Problem in getEelementById() method-null pointer exception
Hi All,
I am using DocumentBuilder factory for parsing a xml file.
I am getting the document object and also creating an element in
the root element .And also I am setting the element id for the
element as attiribute .I need to select the element having same ID
using getElementById() method .But it is giving null pointer
exception.
N.B: My parsing file contains dtd declaration and root element.
My sample code look like this;
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=dbf.newDocumentBuilder();
Document doc=db.parse(ne File("C:/index.xml");
Element root t=doc.getDocumentElement();
root.setAttribute("ID","12345");
Element oElement = doc.createElement(element_name);
oElement.setAttribute("ID",element_id);
Element oEle=doc.getElementById(element_id);
Could anyone please to solve this problem.
Please do favour with me.
Thanks and Regards,
Sreekanthwhile creating xml you should mention which attribute is ID attribute using
setIDAttribute() method,
as you are setting "ID" attribute as ID so
after adding Id attribute to the root element
use setIDAttribute("ID",true);
then getElementById will return the element by using ID
regards
shivakumar.T -
Problem in calling method with object in another class
Hi All,
Please tell me the solution, I have problem in calling a method I am posting the code also
First Program:-
import java.io.*;
public class One
public One()
System.out.println("One:Object created");
public void display()
System.out.println("One:executing the display method");
static
System.out.println("One:executing the static block");
Second Program:-
import java.io.*;
public class Two
public Two()
System.out.println("Two:Object created");
public static void main(String arg[])throws Exception
System.out.println("Two:executing the main method");
System.out.println("Two:loading the class and creating the object::One");
Object o=Class.forName("One").newInstance();
System.out.println(o);
o.display(); //displaying error here in compile time.
static
System.out.println("Two:executing the static block");
waiting for your answer,
thanks in advance,bye.Hi All,
Please tell me the solution, I have problem in
calling a method I am posting the code also
First Program:-
import java.io.*;
public class One
public One()
System.out.println("One:Object created");
public void display()
System.out.println("One:executing the display
method");
static
System.out.println("One:executing the static
block");
Second Program:-
import java.io.*;
public class Two
public Two()
System.out.println("Two:Object created");
public static void main(String arg[])throws
Exception
System.out.println("Two:executing the main
method");
System.out.println("Two:loading the class and
creating the object::One");
Object o=Class.forName("One").newInstance();
System.out.println(o);
o.display(); //displaying error here in compile
time.
static
System.out.println("Two:executing the static
block");
waiting for your answer,
hanks in advance,bye.the line
o.display()
could be written as
((One)o).display();
Maybe you are looking for
-
HT204266 If an app doesnot do what it says it will, can I get my money back ?
If I purchase an app and it doesn't work can I get my money back? How do I go about it?
-
Can someone please shed some light on his log please?
We are running Crystal and one of our customers can't launch the reportviewer java applet. This works for everyone else but them. I need to try and find out if this is a crystal problem or a java problem but don't know enough about the java log (from
-
PLSQL script error - 10g enterprise edition
Hi, I designed the following pl/sql program/script. It completed successfully but skips one record ( I dont know first or last ) only in the middle for loop. I did this on 10g or 11g ( dont remember exactly but one of these two ) enterprise edition.
-
How well does final cut pro 7 run on the new iMac i7?
I have the Mac Pro 1,1 - 2x3 GHz Dual-Core Xeon and I'm wondering if I would notice a better performance upgrading the computer. I do have the AJA Kona 2 for video output to HD screen but am willing to lose it for the nice 27" screen and a faster sys
-
Can't play video when it's type "TV Show"
I've got some videos copied from TV show DVDs. They sync to the iPhone OK, but if I have them set as type "TV Show" in the Get Info tag, they don't show up in video. If I go in iTunes and change the type to "Movie" they suddenly appear and play fin