I'm just a rookie, and I'm trying to learn JSP (I'm using scriptlet), servlet, beans and Ajax.
I'm validating some registration forms by calling a servlet (through Ajax). Every time a character is inserted, the Ajax function is recalled and "value" is sent to a servlet whose job is to check if this value is OK. The servlet gets an HttpSession, then it operates on the passed value and saves it into a bean and finally sets session.setAttribute("bean_name", bean). In JSP I inserted the jsp:usebean tag with scope=session. I got no problem retrieving values, for example <%= bean.getUsername()%>, but the problem is all the form values don't get updated unless I refresh the page.
What could it be?
You make the AJAX call to the Servlet. The Servlet does what it needs to do, and renders a response. However, the AJAX call was made by means of JavaScript, after the page was already rendered.
What you need to do is to edit the JavaScript code that issues the AJAX call. Once the AJAX call takes place, your JavaScript code has to wait until a response is returned from the Servlet, and then use client-side facilities (such as DHTML) to edit the already-rendered page.
Related
When I add things to the Session with Session::put() in my controller action, then that data is not available in my view, with Session::get() when doing AJAX request.
The same problem goes for the Former package, which I use for nice form building. It relies on passing some info via the Session, which is used to mark fields as valid/invalid. This functionality is also not working when using AJAX.
I set a view like always, in my View:
$this->layout->content = View::make('account.login')
For AJAX requests, I do NOT render the normal way with layout, but instead get the specific "content" section of the template and return it:
$this->layout->content->renderSections()['content']
When I do a "normal" request, then Session data works fine.
When I do an AJAX request, then Session data set in the controller DURING the AJAX call is ignored. Any Session data set BEFORE the AJAX call is available.
I'm wondering if Laravel has some issue with Session under AJAX calls, or with the the "renderSection()" method above?
I have checked all the obvious problems:
AJAX request uses the same session ID as non-AJAX request.
GET/POST verbs are used correctly etc.
Replicate:
In CONTROLLER action: Session:put('foo','bar');
In VIEW file (in the content part): Session:put('foo2','bar2');
In VIEW file (in the content part): var_dump(Session::get('foo','bar')); // Returns 'bar' in non-AJAX calls, but returns nothing for AJAX calls (!!!)
In VIEW file (in the content part): var_dump(Session::get('foo2')); // Returns 'bar2' in both AJAX and non-AJAX calls as expected.
It seems like the Session values set in the controller action ARE LOST when it renders the view. Therefore my question if this is 1) an AJAX vs. SESSION issue in Laravel, or 2) an Session vs. renderElement() problem that I am not aware of?
I had the same problem and just found a potential solution:
I found a similar problem relating to laravel 3. For the session to persist in an ajax call you need to return the response correctly.
return json_encode($response);
This is causing the problem. It's not it appears a valid response to enable the session to persist. Change it to:
return Response::json($response);
This enables the session to persist!
For some reason a normal form submit or call to the method allows the first one but ajax does not.
I've seen references elsewhere about echo statements in the method affecting the session - the return I suppose must behaving similar to an echo
This is the post that triggered the solution:
http://forumsarchive.laravel.io/viewtopic.php?id=1304
I recorded a .net application using JMETER. After correlating and playing back it throws the below error. I have seen few posts which says eventvalidation has to be set false. Is there any other way to get rid of this error in Jmeter?
505|error|500|Invalid postback or callback argument.
Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%# Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.
If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
I guess that you're either missing or passing incorrect ASP.NET Viewstate
Basically it's an input of "hidden" type which is required to store application state and some service data which you application is expecting.
My understanding is that you're either using kind of hard-coded or recorded viewstate value or totally missing it.
I recommend to append Regular Expression Extractor Post Processor (or any suitable kind of post-processors line Beanshell, BSF, XPath - if your application talks XHTML) to extract viewstate value from each request, store it in a variable and add it to every next request.
You need to disable event validation in the config
If the dynamic DropDownList in your page, you can try to set blank to the value of DropDownList in JMeter post data. I think this problem can be solved.
I am very new to AJAX and I am stuck with a problem. I have a <div> in my JSP. I have another JSP that is included in the above JSP using <jsp:include>. The problem is that the included JSP does DB operations and it takes a lot of time to render. I want the former JSP to be loaded first and then latter JSP to be rendered in the DIV. I searched but couldn't understand how to resolve it. Basically, I want the former JSP to be displayed and then the latter to be displayed once it completes operations. Currently, the former JSP takes lots of time to load as the latter is included in the former JSP and will render only when the latter JSP has completed loading.
Appreciate your help. :)
I believe this is not the correct approach . The DB interaction part should be done by the DAO classes triggered by some Servlet . Using JSP for DB interactions is bad . Having said that your current problem can be solved by the below approach :
Remove all the DB operations from the JSP.
Keep a div inside your main JSP.
On load , trigger an AJAX call to a Servlet.
Servlet/DAO class performs the DB operations and returns back the result. Store the result in session if needed.
Inside the success handler of the AJAX request function , write a call back function which loads the other JSP file.
Check this answer Load a jsp page using AJAX load method.
The popular approach is to use javascript library such as jQuery and invoke the long-running operation using ajax
$.ajax('/longrunningop', {
type: 'POST',
data: 'a=1&b=2'}).done(function(data) {
// code to display data to div here..
});
Good practice is you code the long running operation to return JSON instead of JSP
Lets say I have couple of filters in my deployment descriptor and each request to the app has to pass through those. There is form with a formbean attached to it. Once I fill the form and click submit, when does the html parameters in the form are binded to the form bean? Before the request is passed through the filters or after passing thorugh the filters?
The reason I am asking is.. I have a form with 20 fields. Once I click submit, 17 values are being binded to the bean properly but 3 values are missing by the team request reaches validate method. I am absolutely clueless has to where the values are missing. I tried to print an enumeration of all the request parameters in validate method and those three fields are there in request object. AFAIK, There is no issue with those three elements name because the app works perfecly in my local IDE but brakes up in test env which makes it all the more difficult to pin-point the issue :(.
I have a JSP page which has a form with an input text. When I submit, it goes to a servlet. The servlet processes and creates some objects and sets in request using request.setAttribute(). It then forwards to a page which has some custom JSP tags which use the objects set in servlet.
I want to replace this by Ajax. I have implemented it as follows:
First, the form is submitted through Ajax using POST, the objects which were set earlier using request.setAttribute() are converted to JSON string and sent as response. On success, there is another Ajax GET call to a JSP page which has my custom tags and the JSON string is passed as parameter. The response of this Ajax call is set inside a div.
But it are two Ajax requests. How can I make it a single Ajax request instead?
As per the comments, you just need to let the first request forward to the desired JSP instead of returning the JSON string which you in turn pass back to the JSP.
request.getRequestDispatcher("/WEB-INF/next.jsp?jsonstring=" + jsonstring).forward(request, response);