How to check the values of view object?
Hi all,
I created a new view object by right clicking my application module. Now when I try to retrieve values
of the attributes of the view object I am getting null pointer exception. How do I check whether the view has
some values in it or not manually using select statement ? I try to find the view in my database at database navigator
but it was not there. Kindly help me out in this.
Thanks,
Phanindra.
Edited by: 887737 on Oct 19, 2011 12:53 AM
Hi,
Right click on application module(yourAM in model project) and press Run,Then you can confirm whether your ViewObject is working or not.
Note:
Generally create viewObject using EO based or Query based how did you create viewObject
See:
http://download.oracle.com/otn_hosted_doc/jdeveloper/1012/bc4j/intro/bc_avo.html
http://www.adftips.com/2010/09/adf-model-creating-view-object-vo.html
Similar Messages
-
How to check the value in Table CDPOS
Mostly I can't see the following fields value in the table CDPOS,
(1) CDPOS-VALUE_NEW
(2) CDPOS-VALUE_OLD
In fact, it should have values, so how to check the values, is there any special method needed?
Thanks and best regards.Ferry Lianto,
Thank you very much for your expertise.
It's helpful to get some contents via FM:CHANGEDOCUMENT_READ_POSITIONS, the problem is, to some kind of DELETION operation, the log in table CDPOS is very simple, I still don't know which contents were deleted even though I found records in table CDPOS.
Is there any other suggestions?
Thanks and best regards. -
How to check the owner of any Object in the database.
How to check the owner of any Object in the database.
Thanks
HimanshuWhat about this ?
SELECT owner,Object_name,object_type FROM all_objects
OR
SELECT owner,Object_name,object_type FROM dba_objects -
How to check the value from user input in database or not?
Hello;
I want to check the value of user input from JtextFiled in my database or not.
If it is in database, then i will pop up a window to tell us, otherwise, it will tell us it is not in database.
My problem is my code do not work properly, sometimes, it tell me correct information, sometime it tell wrong information.
Could anyone help,please.Thanks
The following code is for check whether the value in database or not, and pop up a window to tell us.
while( rs.next()) {
System.out.println("i am testing");
bInt=new Integer(rs.getInt("id"));
if(aInt.equals(bInt)){ // If i find the value in data base, set flag to 1.
flag=1; //I set a flag to check whether the id in database or not
break;
System.out.println("falg" + flag);
if(flag==1){ //?????????????????????
String remove1 = "DELETE FROM Rental WHERE CustomerID=" + a;
String remove2 = "DELETE FROM Revenus WHERE CustomerID=" +a;
String remove3 = "DELETE FROM Customer WHERE id=" +a;
s.executeUpdate(remove1);
s.executeUpdate(remove2);
s.executeUpdate(remove3);
JOptionPane.showMessageDialog(null,"you have success delete the value");
s.close();
else//???????????????????????????????
JOptionPane.showMessageDialog(null,"I could not found the value"); -------------------------------------------------------------------
My whole program
import java.sql.*;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JOptionPane;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class DeleteC extends JFrame
public static int index=0;
public static ResultSet rs;
public static Statement s;
public static Connection c;
public static Object cols[][];
private static JTable table;
private static JScrollPane scroller;
private static int flag=0;
public DeleteC()
//information of our connection
//the url of the database: protocol:subprotocol:subname:computer_name:port:database_name
String strUrl = "jdbc:oracle:thin:@augur.scms.waikato.ac.nz:1521:teaching";
//user name and password
String strUser = "xbl1";
String strPass = "19681978";
//try to load the driver
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
catch (ClassNotFoundException e) {
System.out.println( "Cannot load the Oracle driver. Include it in your classpath.");
System.exit( -1);
//a null reference to a Connection object
c = null;
try {
//open a connection to the database
c = DriverManager.getConnection( strUrl, strUser, strPass);
catch (SQLException e) {
System.out.println("Cannot connect to the database. Here is the error:");
e.printStackTrace();
System.exit( -1);
//create a statement object to execute sql statements
public void getData(String a){
try {
//create a statement object to execute sql statements
s = c.createStatement();
int index=0;
Integer aInt= Integer.valueOf(a);
Integer bInt;
//our example query
String strQuery = "select id from customer";
//execute the query
ResultSet rs = s.executeQuery( strQuery);
//while there are rows in the result set
while( rs.next()) {
System.out.println("i am testing");
bInt=new Integer(rs.getInt("id"));
if(aInt.equals(bInt)){
//JOptionPane.showMessageDialog(null,"I found the value");
flag=1;
break;
System.out.println("falg" + flag);
if(flag==1){
String remove1 = "DELETE FROM Rental WHERE CustomerID=" + a;
String remove2 = "DELETE FROM Revenus WHERE CustomerID=" +a;
String remove3 = "DELETE FROM Customer WHERE id=" +a;
s.executeUpdate(remove1);
s.executeUpdate(remove2);
s.executeUpdate(remove3);
JOptionPane.showMessageDialog(null,"you have success delete the value");
s.close();
else
JOptionPane.showMessageDialog(null,"I could not found the value");
catch (SQLException e) {
JOptionPane.showMessageDialog(null,"You may enter wrong id");
My main program for user input from JTextField.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JOptionPane;
import java.util.*;
public class EnterID extends JFrame{
public JTextField tF1;
public EnterID enID;
public String tF1Value;
private JLabel label1, label2, label3;
private static JButton button;
private static ButtonHandler handler;
private static String aString;
private static Integer aInteger;
private static Integer checkV=0;
public static void main(String args[]){
EnterID eId= new EnterID();
public EnterID(){
handler=new ButtonHandler();
Container c= getContentPane();
c.setLayout(new GridLayout(3,1));
button= new JButton("ok");
button.addActionListener(handler);
label1 = new JLabel(" CustomerID, Please");
label2 = new JLabel("Label2");
label3 = new JLabel();
label3.setLayout(new GridLayout(1,1));
label3.add(button);
label2.setLayout(new GridLayout(1,1));
aString = "Enter Id Here";
tF1 = new JTextField(aString);
label2.add(tF1);
c.add(label1);
c.add(label2);
c.add(label3);
setSize(150,100);
setVisible(true);
private class ButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent event){
tF1Value=tF1.getText();
// CheckData cData = new CheckData();
// aInteger = Integer.valueOf(tF1Value);
if(tF1Value.equals(aString)){
JOptionPane.showMessageDialog(null,"You didn't type value into box");
setVisible(false);
else {
DeleteC dC= new DeleteC();
dC.getData(tF1Value);
setVisible(false);
}You may have working code now, but the code you posted is horrible and I'm going to tell you a much much much better approach for the JDBC part. (You should probably isolate your database code from your user interface code as well, but I'm skipping over that structural problem...)
Do this instead:
public void getData(String a){
PreparedStatement p;
String strQuery = "select count(*) the_count from customer where id = ?";
try {
//create a prepared statement object to execute sql statements, it's better, faster, safer
p = c.prepareStatement(strQuery);
// bind the parameter value to the "?"
p.setInt(1, Integer.parseInt(a) );
//execute the query
ResultSet rs = p.executeQuery( );
// if the query doesn't throw an exception, it will have exactly one row
rs.next();
System.out.println("i am testing");
if (rs.getInt("the_count") > 0 ) {
// it's there, do what you need to...
else
JOptionPane.showMessageDialog(null,"I could not find the value");
catch (SQLException e) {
// JOptionPane.showMessageDialog(null,"You may enter wrong id");
// if you get an exception, something is really wrong, and it's NOT user error
// always, always, ALWAYS close JDBC resources in a finally block
finally
p.close();
}First, this is simpler and easier to read.
Second, this retrieves just the needed information, whether or not the id is in the database. Your way will get much much slower as more data goes into the database. My way, if there is an index on the id column, more data doesn;t slow it down very much.
I've also left some important points in comments.
No guarantees that there isn't a dumb typo in there; I didn't actually compile it, much less test it. It's at least close though... -
HELP !!! How to check the size of an object in Photoshop ?
Hello,
I'm using Photoshop CS 3 to design a website. I used several shapes such as rectangle, line or ellipse of different size. Probably it is a stupid question but I don't know how to check the size of an existing rectangle. I tried free transform tool that selects my rectangle but doesn't show its size. Then I made a selection with rectangular marquee tool but I see nowhere the size of the selected area.
If you know the name of such a tool please help me !
Have a nice day !Web images are all pixels. View at 100% at pixel view. that is your exact size
-
How to check the value of "The Interrupt Status Flag"?
Hi, thank you for reading this post!
Invoking Thread.interrupt() sets the value of the Interrupt Status Flag.
Just wondering if there is a Java method to check the value of this flag? Or is using isInterrupted() or interrupted() the only way to check?
http://download.oracle.com/javase/tutorial/essential/concurrency/interrupt.html
Thank you in advance for your help!
EricBelow is the full code. As soon as the Thread.sleep() is taken out in main(), the interrupt is detected in the child thread. But if the sleep() stays, then the child thread goes into an infinite loop. It's not detected the interrupt.
//ParentInterruptChildThreadCatchedDemo.java
//Program function: This program demonstrates the parent thread (main()) interrupting a child thread (thread1).
//Threaded class
class TryThread extends Thread {
//fields
private String threadname;
private long aWhile;
//Constructor
public TryThread(String tname, long delay) {
threadname = tname;
aWhile = delay;
//run() method
public void run() {
while(!Thread.interrupted()) {
//Do work
try {
System.out.println(Thread.currentThread().getName() + " was just interrupted!");
throw new InterruptedException();
} catch(InterruptedException e) {
//System.exit(1);
return;
public class ParentInterruptChildThreadCatchedDemo {
public static void main(String[] args) {
Thread thread1 = new TryThread("thread1", 2000L);
thread1.start();
try {
System.out.println("main() goes to sleep for 10 second.");
Thread.sleep(10000);
System.out.println("Statement after main() sleep().");
} catch(InterruptedException e) {
e.printStackTrace();
//Interrupt thread1
int interruptFlag = 5;
for(int i=0; i<11; i++) {
if(i == interruptFlag) {
System.out.println("Condition met, going to interrupt thread1 ...");
thread1.interrupt();
System.out.println("Thread1 interrupted!");
System.out.println("Ending main()");
/*Output:
main() goes to sleep for 10 second.
Statement after main() sleep().
Condition met, going to interrupt thread1 ...
Thread1 interrupted!
Ending main()
INFINITION LOOP
*/ -
How to print the values of type Object?
Hi All,
I am not able to print values of the following can anyone telme where i am wrong and what i can do in this regard.
Object one = request.getAttribute("values");
When i try to print these values as following
System.out.println("one ="+one);
am not getting the values in a different format something like [Ljava.lang.String;@1234f. I tried to convert the following Object to String still its not working. Can some one please suggest me what i can do in this regard.
Thanksferrari_sun wrote:
I am getting a Null pointer exception if i typecast it to a string array. Not sure what to do nowThe hell you are. You don't get Null pointers out of casting. However you might be accessing null elements of the array afterwards.
You really should throw away the code, go fetch some "How to learn basic Java with Wiggles The Bear" ebook and then start learning the basics instead of tripping on every single line of your code which is too complicated for you. -
How to check the value of a string is numeric, alphanumeric or characters?
Hi All,
I have a task to validate an employee Id. Suppose the employee Id is E121212. Now as per the validation rule I need to check "the first letter of the employee Id is a character and rest are numbers." How can I do this? Please reply.
Thanks & Regards
Bibhuprasad Soumyaranjan>
Hi Bibhuprasad,
I have a task to validate an employee Id. Suppose the employee Id is
E121212. Now as per the validation rule I need to check "the first letter
of the employee Id is a character and rest are numbers." How can I do this? Please reply.Everyone else has proposed REGEXP_LIKE, and while it's very powerful, it is
also very CPU intensive. You should always use Oracle's string functions
instead of Regular Expressions if possible.
I played around with
WITH data
AS (SELECT 'E11212' s FROM DUAL
UNION ALL
SELECT '121212' FROM DUAL
UNION ALL
SELECT 'EE121212' FROM DUAL
UNION ALL
SELECT 'É121212' FROM DUAL
UNION ALL
SELECT 'E1EEEEEEEE' FROM DUAL
UNION ALL
SELECT 'E134343444' FROM DUAL)
SELECT s,
CASE
WHEN (SUBSTR(s, 1, 1) BETWEEN 'A' AND 'Z') -- AND (TO_NUMBER(SUBSTR(s, 2, LENGTH(s)), 999999) > 111111)
THEN 'Correct Format'
ELSE
'Incorrect Format'
END mySSN,
SUBSTR(s, 2, LENGTH(s)) AS theNumber
FROM data;I think that this can be worked so that it willl go what you require without using
REGEXP_LIKE.
HTH,
Paul...
Bibhuprasad Soumyaranjan -
How to check the value entered in one co from anethor CO
Dear All,
I have a Debrief screen in which one main region is attached to CO1 and a tab region is attached to CO2, the tab region is an independent region in the main rdebrief main RN,
Here i have a requirement if one of the field of the tab region is entered , that has to be captured in the Debrief main Region CO.
could you help in assisting this.
Regards
AKAK,
You can get handle of any item in the page from the mainCO by getting handle of the bean. You will have to get the handle of the tabbed region and get the handle of the corresponding field.
Alternatively, you can get the value from the VO Attribute, if the field is mapped to a VO attribute.
Cheers
AJ -
How to check the value of the structure component at run time
Dear Friends,
Kindly, through some idea for the below query:
Step 1: I have a structure name as STRUCT with components COMP1, COMP2, COMP3,......, COMP99. At run time in this structure few components may have values and few may not have.
Step 2: Now I have a variable of type char name as LV_CHAR, at run time this variable may have value as any of the structure components given in the above step such as COMP1 or COMP2 or .....or COMP99.
Step 3: Let us assume the variable LV_CHAR have value COMP11 and now I need to check whether the strucutre componet STRUCT-COMP11 is initial or not using this variable.
Could you please give me the steps what needs to be done to handle it.
Thanks & regards,
Mallikarjuna M.PatanGova wrote:
Hi,
Can someone help me out to divide a Hexadecimal number say"ABCD" and display
1) each value of hexadecimal number like 'A','B','C','D' in separate indicators and
2)each value of hexadecimal number like 'A','B','C','D' into their respective decimal number and to show in separate indicators.
Thanks.
That has absolutely nothing to do this thread. Start a new thread.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines -
How to check a value for paramter query
I am passing a paramter value from my text box to my sql statement and I would like to check if the value is entered into a text box. If you have any idea please share it with me, i have been struggling with this for many days.Code below is how i try to check if the value is entered but I do not know how to check the value in the :VendorName
thanks
If Not txtVendorName.Text = "" Then
Sql = Sql & " AND (Upper(V.VNAMEL) LIKE '%' || Trim(Upper(:VendorName))|| '%') "
End IfSorry guys english is not my first language and i will try to be clear and specific.
I have a search page where customeres can do searching either using a text box or two dropdowns i have on my page. they have the option of doing search either using a text box or dropdowns or both.Everything seems to work fine but if users does not leave the text box blank. but they leave the text box blank and do searching using the two dropdowns then the page comes up empty and i checked my query and i should get a value. Attacehed my code for you to look at it.
<pre>
Sub VendorSearch()
gvSearch.Visible = True
Dim MinPDate As String = drPur.SelectedItem.ToString
Dim MaxMDate As String = drPurM.SelectedItem.ToString
Dim liThisOne As ListItem
Dim strState As String = ""
For Each liThisOne In lstState.Items
If liThisOne.Selected Then
strState = strState & "'" & liThisOne.Value & "'" & ","
End If
Next
Dim Sql As String = " SELECT distinct V.VENDOR ""Vendor Id"",R.ADDRNUM,V.VNAMEL ""Vendor Name"",R.AADDR1,R.ACITY,R.VASST1, "
Sql = Sql & "R.ASTATE State,R.AZIPCODE, to_char(Max(P.DATEPUR),'YYYY/DD/MM') ""Plan Purchased Date"" , "
Sql = Sql & "TRIM (r.aaddr1 || decode(trim(r.aaddr2),null,'',' - ') || r.aaddr2) Address,"
Sql = Sql & " substr(decode(trim(r.vasst1),null, 'N/A','000/000-0000?','N/A','000/000-0000','N/A', r.vasst1),1,12) Fax, "
Sql = Sql & " substr(decode(trim(r.aphone),null, 'N/A','000/000-0000?','N/A', r.aphone),1,12)Phone "
Sql = Sql & "FROM VENDOR V,VENDADDR R, PLANHOLD P "
Sql = Sql & "WHERE V.VENDOR = R.VENDOR AND P.VENDOR = R.VENDOR "
Sql = Sql & " AND (P.DATEPUR >= TO_DATE('1999-01-01','YYYY-MM-DD')) "
Sql = Sql & "AND P.DATEPUR In ( select Max(P.DATEPUR) from PLANHOLD P where P.vendor = R.VENDOR) "
'If txtVendorName.Text <> "" Then
' Sql = Sql & " AND (Upper(V.VNAMEL) LIKE '%' || Trim(Upper(:VendorName))|| '%') "
'End If
If (strState.Length > 0 And lstState.SelectedIndex <> 0) Then
strState = Left(strState, strState.Length - 1)
strState = "(" & strState & ")"
Sql = Sql & "AND R.ASTATE IN " & strState
End If
If (drPur.SelectedIndex <> 0 And drPurM.SelectedIndex <> 0) Then
Sql = Sql & " AND to_number(to_char(p.datepur, 'YYYY')) between " & "'" & MinPDate & "'" & " AND " & "'" & MaxMDate & "'"
End If
' Dim Para As String
' SqlDataSource1.SelectParameters.
If Not txtVendorName.Text = "" Then
Sql = Sql & " AND (Upper(V.VNAMEL) LIKE '%' || Trim(Upper(:VendorName))|| '%') "
End If
'If Not IsDBNull(SqlDataSource1.SelectParameters(":VendorName")).val Then
' Sql = Sql & " AND (Upper(V.VNAMEL) LIKE '%' || Trim(Upper(:VendorName))|| '%') "
'End If
Sql = Sql & " AND V.VOBSOLET = 'N' "
Sql = Sql & "GROUP BY V.VENDOR, R.ADDRNUM,V.VNAMEL,R.AADDR1,R.AADDR2,R.ACITY,R.ASTATE, R.AZIPCODE, R.APHONE, R.VASST1, P.DATEPUR "
Sql = Sql & "ORDER BY V.VENDOR "
Response.Write("Sql " & "<br/>" & Sql & "<hr/>")
SqlDataSource1.SelectCommand = Sql
End Sub
</pre> -
How to Get the value in a new created view.
Hi Experts,
I have create a view along with the fields: Street No. , Street name, apt no,
how should i capture these values . in a current situation i entering the value but when i check in the debugging mode : in a collection_wrapper (context node class) i am not able the see the value which i have entered. please help me out. it is very urgent.
RohitHi Ashish,
Thanks for replying. i have already create the context node and in the using the request from field method ,i am getting the value in my work area but how to store the value in the custom fields of that particular order as well as store the value in the crmd_customer_i table...
Regards,
Rohit -
How to reference the value of a af:inputText at View level in a java clas
How to reference the value of a <af:inputText> at View level in a java class at Model level? Thanks!
Create AppModuleImpl class and create ther for example setMyParam procedure.
(You can use AppModule. There simple interface to do this classes
In JDev 11:
1. Go to AppModule and in Java bookmark generate application module class.(AppModuleImpl.java)
2. Put "private String myParam;" and method to access myParam "public void setMyParam(String myParam)".
3. Again in the AppModule in the Java bookmark add method to client interface.
AppModuleImpl.java
public class AppModuleImpl extends ApplicationModuleImpl implements AppModule {
* This is the default constructor (do not remove).
private String myParam;
public AppModuleImpl() {
//this.
public void prepareSession(Session session)
super.prepareSession(session);
myParam = myParam + myParam;
public void setMyParam(String myParam) {
this.myParam = myParam;
prepareSession(getSession());
AppModule.java
public interface AppModule extends ApplicationModule {
void setMyParam(String myParam);
AppModuleClient.java
public class AppModuleClient extends ApplicationModuleImpl implements AppModule {
* This is the default constructor (do not remove).
public AppModuleClient() {
public void setMyParam(String myParam) {
Object _ret =
this.riInvokeExportedMethod(this,"setMyParam",new String [] {"java.lang.String"},new Object[] {myParam});
return;
And you can use method setMyParam as you wish :))) You can find it in AppModuleDataControl..
Edited by: Victor_V_S on Jun 5, 2009 1:31 AM
Edited by: Victor_V_S on Jun 5, 2009 1:33 AM
Edited by: Victor_V_S on Jun 5, 2009 7:30 AM -
How to get the values from object ?
hi everybody,
i am experimenting with oops concept. first have a look at these coding and then tell me this.
what do i have to do to get the value of an object created. i want to use the get method to get the name, food and quantity, without the use of the created object. i mean i want to make the process independent of how many objects i make so that i can find a value given the name of a person in the object.
when this is done, i want to use this to create filed of a specific doc format for each object created. now when we are using the get method i want to read whats on the object value .
Am i being clear or are thing very confusing, please let me know wht u think so i can clarify myself more.
public class obj {
String name;
String food;
int quantity;
public void set(String ndata, String fdata,int qdata )
this.name=ndata;
this.food=fdata;
this.quantity=qdata;
public void get()
System.out.println( this.name+" "+this.food+" "+this.quantity);
public static void main(String[] args) {
obj obj1= new obj();
obj1.set("varun", "burger", 2);
obj obj2= new obj();
obj1.set("roshan", "diet pepsi", 1);
obj obj3= new obj();
obj1.set("aman", "biryani", 2);
obj2.get();
}cyberpanther wrote:
hi everybody,
i am experimenting with oops concept. first have a look at these coding and then tell me this.
what do i have to do to get the value of an object created. i want to use the get method to get the name, food and quantity, without the use of the created object. no. wrong.
i mean i want to make the process independent of how many objects i make so that i can find a value given the name of a person in the object.no. sounds more like you're experimenting with drugs.
when this is done, i want to use this to create filed of a specific doc format for each object created. now when we are using the get method i want to read whats on the object value .
Am i being clear or are thing very confusing, please let me know wht u think so i can clarify myself more.you're clearly confused.
public class obj {
String name;
String food;
int quantity;
public void set(String ndata, String fdata,int qdata )
this.name=ndata;
this.food=fdata;
this.quantity=qdata;
public void get()
System.out.println( this.name+" "+this.food+" "+this.quantity);
public static void main(String[] args) {
obj obj1= new obj();
obj1.set("varun", "burger", 2);
obj obj2= new obj();
obj1.set("roshan", "diet pepsi", 1);
obj obj3= new obj();
obj1.set("aman", "biryani", 2);
obj2.get();
}utterly awful code. this is how it should not be done.
% -
How to get the values of the objects inside an object??
Hi,
I am trying to write code to display name and memory usage of all session attributes, in a recursive way.
I suppose reflection is needed here, but I cant figure out how to get the values of the objects inside an object...
private void handleIt(String attributeName, Object attributeValue) {
boolean isPrimitiveOrNull = ((null == attributeValue) ||
(attributeValue.getClass().isPrimitive()));
if (isPrimitiveOrNull) {
sb.append("{" + attributeName + ":" + sizeOf(attributeValue) + "}");
} else {
sb.append("{" + attributeName + ":" + sizeOf(attributeValue) + "{");
Field[] fields = attributeValue.getClass().getDeclaredFields();
int lim = fields.length;
String name;
Object value = null;
for (int i = 0; i < lim; i++) {
name = fields.getName();
//LOOK AT THIS LINE: !!!!!!!!!!!!!!!!!!!!!!!!!!!
value = fields[i].get(obj); //I don´t know what 'obj' should be??
handleIt(name, value);
sb.append("}");
Any suggestions will be greatly appreciated...I realized that massive int objects called MAX_VALUE, MIN_VALUE and SIZE where causing the StackOverflow, so I removed them from the analysis.
This is the resultant code. But I think it isnt accurate in calculating the real size of objects being got using reflexion.
Do you or somebody have any more suggestions?
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.lang.reflect.Field;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class SessionMeasurer extends HttpServlet {
private static final long serialVersionUID = 1470488362727841992L;
private StringBuilder sb = new StringBuilder();
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
performTask(request, response);
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
performTask(request, response);
public void performTask(HttpServletRequest request, HttpServletResponse response) {
HttpSession session = request.getSession(false);
String attributeName = "";
Object attributeValue = null;
for (Enumeration<?> attributeNames = session.getAttributeNames(); attributeNames.hasMoreElements();) {
attributeName = (String)attributeNames.nextElement();
attributeValue = session.getAttribute(attributeName);
handleIt(attributeName, attributeValue);
System.out.println(sb.toString());
private void handleIt(String attributeName, Object attributeValue) {
if (attributeValue != null) {
boolean isPrimitive = attributeValue.getClass().isPrimitive();
if (isPrimitive) {
sb.append("{" + attributeName + ":" + sizeOf(attributeValue) + "}");
} else {
sb.append("{" + attributeName + ":" + sizeOf(attributeValue) + "{");
Field[] fields = attributeValue.getClass().getDeclaredFields();
String name;
Object value = null;
int lim = fields.length;
for (int i = 0; i < lim; i++) {
name = fields.getName();
if (!name.endsWith("_VALUE") && !name.equals("SIZE") && !name.equals("serialVersionUID")) {
try {
value = fields[i].get(attributeValue);
} catch(Exception e) {
//PENDIENTE: Tratamiento excepción
handleIt(name, value);
sb.append("}");
private int sizeOf(Object obj) {
//Valid only for Serializables
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = null;
byte[] bytes = null;
try {
oos = new ObjectOutputStream(baos);
oos.writeObject(obj);
bytes = baos.toByteArray();
} catch(Exception e) {
//PENDIENTE: Tratamiento excepción
} finally {
if (oos != null) {
try {
oos.close();
} catch(Exception e) {
//PENDIENTE: Tratamiento excepción
if (baos != null) {
try {
baos.close();
} catch(Exception e) {
//PENDIENTE: Tratamiento excepción
int size = -1;
if (bytes != null) {
size = bytes.length;
return size;
Maybe you are looking for
-
I get the sound of a door opening and closing intermittenly.
I get the sound of a door opening then closing at different times. It sounds like it signals when someone is getting online and when they leave. What is this and how do I turn it off or find out who it is?
-
Shuffle does not show up on desktop or in iTunes
Older iPod Shuffle (2nd version) does not appear on desktop or in iTunes. It does play with earbuds attached so I know it is functioning.Have tried all the suggestions to no avail. Thanks, Pete
-
Setting different text colors within 1 formula field
Post Author: hassan.annous CA Forum: Formula Suppose I am interested in coloring each part of a text returned by a formula field with a different color. For example I have the following string: Local StringVar Diagnosis := "I am trying to color my te
-
i get this message when im trying to impor psd. file or ai. file with no text in them. actually any file i try to import! i tried to do what is written on the adobe web.. but nothing seems to be working. can you help me please?
-
After upgrading from ios 7 I was unable to activate my iphone 5
after recent upgrading from ios 7,Iwas unable unlock the sim card as well as not been able to activate my phone