I read JEE6 doc and confused with : Does container managed entity manager (injected by PersistenceContext annotation) is thread-safe in stateless session bean in multiple-thread env?
See code below, if there are 2 requests to stateless sesion bean in 2 concurrent threads , is it using same Entity Manager Instance or not?
@Stateless(name = "HRFacade", mappedName = "HR_FACES_EJB_JPA-HRFacade-HRFacade") public class HRFacadeBean implements HRFacade, HRFacadeLocal { @Resource SessionContext sessionContext;
I'm training myself with the EJB 3 technology. I would like to create a stateless bean that instead of returning a String, it returns an object. I tried in the same way I did with the first exercise, but I'm getting several errors.
But resource.returnString(r); gives a org.apache.jasper.JasperException: java.lang.NullPointerException I started the glassfish server in debug mode and found out that "resource" was null. but @PostConstruct in singleton does print which means singleton bean exists.
Can we call singleton beans with no interface in such a way form a session bean? I actually want to acquire instance of singleton bean when a client invokes method in Client bean...
I have tried this example ([URL].../) with CarDao extending the BaseDao, it works like a charm.However, from the CarDao class, my NetBeans underlined the class name “CarDao” with the error message “A session bean must not extend another session bean.” But I can compile, deploy and run the application without any problem.
I have also heard that a session bean cannot extend another session bean, but why it works here?
I am using Java EE 6, NetBeans 8.0.1 and WebLogic 12c for this code testing.
When i create an application Bean how i can update it from another bean? Lets say application Bean has variable h=1 and i want to update from another bean and make it 2 how i can do it? And how i can access the value of a session bean from another bean?
In stateful session bean client servlet we are explicitly setting shoppingCart to session attribute. I do not remember doing similar step withStatelessSession bean.
In my case my managed bean is View Scoped and it supports a UI page which has multiple forms and each form is submitted as AJAX POST request.
As per the statndard, setting restriction to 5 should create 5 views and after that based on LRU algorithm the oldest views should get deleted if 6th views is created.
Therefore any action on the oldest view will throw the ViewExpiredException and i simply redirect the user to view expired page.
1) When i set the restriction to 5 views, i open 4 tabs with 3 forms each. 2) I submit the 3 forms on first tab everything works fine. 3) As soon as I go to 2nd tab and submit the first form thr, i get view expired exception 4) It seems I am exceeding the number of views I mentioned in web.xml
I want to know :
1) Does every AJAX POST submit itself creates a view ? 2) How I can count the number of views created in a session ? 3)Can i force expiry of a view in JSF 2.0.2 while the session is still alive ? 4) Normally JSF 2.0.2 session cachces the views. Lets assume session is alive the entire day but a view was created in morning at 9:00 AM and is not used again the entire day. Assuming that session doesn't reaches the max number of views it can save in entire day, will the view created in morning expire on its own after certain interval of time ? If not , can we still force its expiry while keeping the session alive ?
I'm new to JSP but I've to use it to grab data coming from an external site, pass data to a Bean, write data in a DB and redirect the user to another page. Follow the JSP page.
<%@page import="EJB.getResponse"%> <% long paymentID = Long.parseLong(request.getParameter("paymentid")); String responsecode = "9999"; getResponse g = new getResponse();
[Code] ....
This is the bean:
@ManagedBean @RequestScoped public class getResponse implements Serializable { private Long paymentId; private String result; private String auth;
[Code] ....
On the console I see the prints but I receive the NullPointerException
WARNING: StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception java.lang.NullPointerException at EJB.getResponse.printData(getResponse.java:72) at org.apache.jsp.notify_jsp._jspService(notify_jsp.java from :60) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
May be I did not understand the meaning and usage of attribute "session" in page directive. My understanding is if session=false, in page directive, then the JSP page will not participate in the session. However, I have my welcomepage as below:
Can I access the session object even session has been expired? I need to check whether session is expired or not for each request.The session invalidation is set null the session object. What I concluded, session time out I can access session object but session invalidation I can not access session object. How can I find the session time out by using session object?
1) From War A, I login to the application and then fetch some users that is a rest call. I get the response back from rest in json form that ui consumes and display the data on page.
2) Now I click on the logout link from ui jsp. This logs out the session from Ui. I use <form data-dojo-type="dijit/form/Form" based logout.
3) I then go to the proxy (using burp) and manually request the rest call which I made in step no 1), the rest gives the response back with the same json object returned in step no 1) This shows that the logout action on step 2) is invalidated the session from War A (ui war) but the session or cookie based from WAR B (rest war) is not invalidated.
Expected outcome:After I Logout from War A(ui war), the session must also get invalidated from war B (rest war) and manually request from proxy should not get the same response object as received in step 1)
I am developing a e-commerce college project, here i add the items in the cart(a div tag in the jsp page) via servlet by creating sessions,
flow control: shopping jsp (when user wants to add an item in the cart) --> item servlet (which is used to create session and synchronized it) --> cart servlet(which is used to add items in the arraylist and show them in the shopping.jsp's div tag + it also sets the total purchase amount in the session variable "totalpurchase")
now after that user wants to proceed to checkout, here i use the onclick event to check the minimumshopping amount must be less than the totalpurchase (totalpurchase which i had setted in the session),but my jsp page is unable to rechognise the updated value of the totalpurchase, yes, if i reload the page, it rechognises the new updated value of the totalpurchase? but i want it to rechognise the updated total purchase value, without reloading he jsp page..
I am reading input from a file that has following information:
line 1 = numbers of integers in array, line 2 = elements in array1, line 3 = elements in array2.
These lines constitute a test case. There are 1000 test cases in the input file.
So basically, I read the length of arrays, populate the arrays by reading from the file.
The code is below ( I have not included reading input code):
while(test_case<1000){ if (count == 1){ //count keeps track of lines in input file vec_length = Integer.parseInt (tokenizer.nextToken()); count++; continue; } if (count == 2){ //populates array1 vector1 = new int[vec_length]; for (int i = 0; i < vector1.length; i++) vector1[i] = Integer.parseInt (tokenizer.nextToken()); count++; continue; }
Array2 is populated using the same as above code. However when I use the following code:
for (int i=0; i<vec_length; i++) temp += vector1[i]*vector2[i];
I get " local variable vector1 and vector2 have not been initialized error". But both arrays have been initialized in the if{} block. Is it because initialization was local to if block?
As a studyproject I'm currently writing a class the allows me to get al fun dates (like when eastern is in a given year, what day a given date has, calculate the date of tomorrow).
While working on the following method:
public String getNextDate (int day, int month, int year) { String nextDate; int nextDay = getNextDay(day, month, year); int nextMonth = getNextMonth (day, month, year); int nextYear = getNextYear (day, month, year); return nextDate = "the day after " + month +"-" + day + "-" + year + " is " + nextMonth + "-" + nextDay + "-" + nextYear + "."; }
I get a notion in my lovely IDE (eclipse) reminding me I'm not using nextDate ("The value of the local variable nextDate is not used"). But I feel I really do use nextDay here. So either I'm making a coding(style) mistake giving me this notion or I should just ignore this notion.
you can also refer this link Local variables in java?Local variables in java?To meet temporary requirements of the programmers some times..we have to create variables inside method or bock or constructor such type of variables are called as Local Variables.
----> Local variables also known as stack variables or automatic variables or temporary variables
----> Local variables will be stored inside Stack.
-----> The local variables will be created while executing the block
in which we declared it and destroyed once the block completed. Hence the scope of local variables is exactly same as the block in which we declared it.
package com.javatask.in; class A{ public static void main(String args[]){ int i=0; // Local variable
Here, I have just tried out to take a value from the database and storing it into local variable then I want to have that value in the value attribute of <input> tag but somehow, I can't get it..
Here, below is my code..
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ page import="java.sql.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL]...."> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
I edited some lines from "[URL] ...." and saved it as html file; now if a friend want to do a search in Wikipedia for cats, the edited page should show up instead of original page.Is there a way to do this using java script.
Let's say I have a loop that loops through objects in an ArrayList then does stuff with them. Is it better for me to store the object in a temporary local variable and do stuff with it, or always use the ".get(arrayindex)" thing?
How to check if a web page is synchronized on a local server in JSP ? I have tried to make database updation synchronized in jsp but how can i check it on local web server (tomcat) ? I have used Oracle database.
More Info:
Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con=DriverManager.getConnection("jdbcracle:thin:@localhost:1521:xe","username","password"); balance=balance-1500; String query1= "update bank set bal=? where card_no='"+cnumber+"'"; PreparedStatement st1 = con.prepareStatement(query1); st1.setString(1,String.valueOf(balance)); int qresult1 = st1.executeUpdate();
This is some of the code in which I have not applied any synchronization. In simple words, I want to know how to test if synchronization part is really working or not ?
My main motive is... I am trying to make an admission form and I want a limited number of seats but I want after every registration process my database updates the seat numbers accordingly and show the right information about how many seats are left to the user. (though in the given code i am just changing the balance)
Like in this example <%! PreparedStatement pst = con.prepareStatement("query"); %> synchronization <% synchronized(pst) { pst.setXXX(...); pst.setXXX(...); pst.executeXXX(...); } %>
Basically this code is supposed to create an int array of 50 elements, then pull the elements listed in positions 1-6 to make a lottery draw.
Problem is it gets down to that last "For" statement and then says "duplicate local variable i." If I attempt to separate it from the previous for loop with curly braces, then it gets mad and says it doesn't know what "local variable i" even IS. So I tried changing it to "j" in the last statement and it couldn't recognise that either. I feel like I need to change the variable name in that second for loop but I'm not sure how to make it understand that the second variable is going to be outputting the values from the first variable.
public class Lottery { public static void main(String[] args) { // TODO Auto-generated method stub int []nums = new int [50]; for (int i = 1; i <50; i ++) {nums[i] = i;}
I have a question regarding best practice in using local variables as my method return variable. I have a method like this:
myReturnObject getMyObject(String input) { myReturnObject myObject = null; try { myObject = helperObject.someOtherMethod().getObject(input); //getObject has return type myReturnObject } catch (Exception e) { //log any problems } return myObject; }
And I'm wondering if I rewrite like this if I'll see some performance optimization benefit:
myReturnObject getMyObject(String input) { try { return helperObject.someOtherMethod().getObject(input); //getObject has return type myReturnObject } catch (Exception e) { //log any problems } return null; }
myObject can be quite large -- so I'm wondering if I can omit the myReturnObject local variable instance if it'll save some work from the garbage collector.