1 . HTML Table data will disappear after page refresh?
 

Answer :
<script type="text/javascript">
   $( document ).ready(function() {
$.getJSON("http://localhost:8080/Service/Rest/cart/get/cart",function(data)
        {
            var tb = $("#tab");
            $.each(data,function(i,value)
            {
                tb.append("<tr><td>Product Name: " + value.name + "</td><td>Price: " + value.price + "    </td><td>Description: " + value.description + "</td></tr>");
            });
        });
});
 $("#btnSearch").click(function() 
    {
        $.getJSON("http://localhost:8080/Service/Rest/cart/get/cart",function(data)
        {
            var tb = $("#tab");
            $.each(data,function(i,value)
            {
                tb.append("<tr><td>Product Name: " + value.name + "</td><td>Price: " + value.price + "    </td><td>Description: " + value.description + "</td></tr>");
            });
        });
    });  
</script>

Leave a Comment

Name  
  Email   
Message
46 . How do I send data via an Ajax Query to a Controller and then open a new JSP page as the Controller's return type?

Answer :

Add the success callback function to your ajax like so:

$.ajax({
         type: "POST",
         url: "/message1",
         data: { 
                 message: hello, 
               }, 
         datatype: 'json',
         success: function(data){
               if(data === "NewPage"){
                    //Open new page
               }
         }
      });
}

47 . Integrate TomCat and Node server?
 

Answer :

For one, you really shouldn't serve angular pages dynamically. Even if you do serve them from node, serve compiled static pages instead of ng serve - for security, performance and other reasons.

With that said, sure you can do this. This depends a little on your setup, but what it comes down to is that you need to proxy all the angular pages to node server. This has not a lot to do with Angular itself.

So, the easiest way to do this is to tell Apache (or nginx or whoever is in front of your Tomcat) to proxy all 404s to the node server. Then node will render angular site, and this in turn will match the url and render the given page, or if not found, render it's own version of 404.

Alternatively, give your apache or whatever, a specific list of URLs (that are already ported) to pass through to node server.

If you don't use Apache, but are serving things out of Tomcat directly (you shouldn't),


48 . Should I learn PHP or JSP?

Answer :

jsp/servlet, because you already know java the more you use java, the more you will become expert with java api, if you switch to php you will have to learn new api, php api/library you will have mediocre java api knowledge and mediocre php api knowledge, and you might forget one of them and only know one of them in mediocrity. 


If you always stick with java, java api will be planted like a glue into your brain, never forgotten, one day you will have hardcore java api knowledge


49 . Can we use JSP with PHP?

Answer :

SP and PHP have similarities, but they can not be used together in the same file. 

It is possible (but unusual) to have a web server that can handle either type of file (probably based on the filename extension), so you'd be able to write a PHP website that calls a JSP website and vice versa. 

But you usually have to pick one or the other and just stay with that. 

My recommendation would be to leverage your PHP knowledge. Learn Object Oriented PHP and Zend. You may discover that OO PHP and Zend will satisfy what you like about Java. 

If you need to go out looking for a job, you'll find that employers tend to divide into various camps. The camps that run PHP do not care how much Java or JSP you know, and the camps that run JSP do not care how much PHP you know. 

It's always a good idea to have a broad base of knowledge of multiple disciplines, but they're generally looking for specialists with deep knowledge in just one or two things. Not always of course, but in general.


50 . Explain 4 scopes of jsp ?????

Answer :

The availability of a JSP object for use from a particular place of the application is defined as the scope of that JSP object. Every object created in a JSP page will have a scope. Object scope in JSP is segregated into four parts and they are page, request, session and application. 

page----- 
‘page’ scope means, the JSP object can be accessed only from within the same page where it was created. The default scope for JSP objects created using <jsp:useBean> tag is page. JSP implicit objects out, exception, response, pageContext, config and page have ‘page’ scope. 
request----- 
A JSP object created using the ‘request’ scope can be accessed from any pages that serves that request. More than one page can serve a single request. The JSP object will be bound to the request object. Implicit object request has the ‘request’ scope. 
session---- 
‘session’ scope means, the JSP object is accessible from pages that belong to the same session from where it was created. The JSP object that is created using the session scope is bound to the session object. Implicit object session has the ‘session’ scope. 
application------ 
A JSP object created using the ‘application’ scope can be accessed from any pages across the application. The JSP object is bound to the application object. Implicit object application has the ‘application’ scope.



51 . Error on string literal jsp?
 

Answer :

in Java String literals are not allowed more than one line .

so you can do using '+' like

String sql= "SELECT m.month,IFNULL(x.cnt, 0) AS cnt FROM "+
" (SELECT 1 AS month UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 10 UNION SELECT 11 UNION SELECT 12) AS m "+
" LEFT JOIN (SELECT DATE_FORMAT(date, '%c') as month, COUNT(*) AS cnt FROM ssl_sales where YEAR(date)=2017 AND status_ssl='new' GROUP BY month) AS x ON m.month = x.month "+
" ORDER BY m.month DESC";

or write it in one line

String sql="SELECT m.month,IFNULL(x.cnt, 0) AS cnt FROM (SELECT 1 AS month UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 10 UNION SELECT 11 UNION SELECT 12) AS m LEFT JOIN (SELECT DATE_FORMAT(date, '%c') as month, COUNT(*) AS cnt FROM ssl_sales where YEAR(date)=2017 AND status_ssl='new' GROUP BY month) AS x ON m.month = x.month ORDER BY m.month DESC";

 


52 . Enable the multiple checkbox using Id?
 

Answer :

I have tried to toggle the checkbox also, So once any checkbox is checked all other are checked and it will unchecked when you clicked on the checked checkbox.

It may also disable the checkbox.

$(document).ready(function() {
  $("input[type=checkbox]").on("click", function(e) {
    var index = 1;
    var status = true;
    $('#canReadFlag' + index + ',#canShareFlag' + index + ',#canUpdateFlag' + index + ',#canDeleteFlag' + index + ',#canCreateFlag' + index).prop('checked', status);

    $('#canReadFlag' + index + ',#canShareFlag' + index + ',#canUpdateFlag' + index + ',#canDeleteFlag' + index + ',#canCreateFlag' + index).prop('disabled', status);
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<input type="checkbox" id="canReadFlag1" name="canReadFlag1" value="1">Can read
<input type="checkbox" id="canShareFlag1" name="canShareFlag1" value="1">Can share
<input type="checkbox" id="canUpdateFlag1" name="canUpdateFlag1" value="1">Can update
<input type="checkbox" id="canDeleteFlag1" name="canDeleteFlag1" value="1">Can delete
<input type="checkbox" id="canCreateFlag1" name="canCreateFlag1" value="1">Can create

53 . How to create website in java without jsp?

Answer :

 JSP is just an application framework *intended* to simplify the use of the J(2)EE servlet specification for the view aspects of apps built using the MVC architectural pattern. JSPs are compiled (by the servlet container) to generate...you guessed it - servlets! 

You absolutely CAN use the original, base, J(2)EE servlet model to develop websites without employing JSPs at all. It will require that you write your own code to implement the interface HttpServlet:

Probably, you'll want to start your own subclassing from the level of the extending, implementing J(2)EE classes HttpServletRequestWrapper and -ResponseWrapper:

You're going to need to write your own code to handle things related to the view layer, to replace things that are already included in the JSP model. I'd suggest you look into some sort of view template framework (google "java view template" for suggestions). 

Been there -done that. If you need more hints, ask (I ain't a big fan of JSP - I like customized templating frameworks).


54 . What is different between asp and jsp?

Answer :

JSP and ASP do have some basic concepts in common. They both make use of simple sever-side scripting to provide access to Web server information and functionality. They both do so using object oriented scripting. And they both started out with similar styles of delimiting this scripting from a page's content. In fact, Microsoft is replacing ASP with ASP+, which is even more like JSP than ASP in that its pages are compiled upon request and run in a 'virtual machine' (which supports multiple languages and is written in C#). 

Yet while ASP primarily supports two scripting languages -- JScript and VBScript -- JSP actually supports real Java code, not a new scripting language. The difference is that the Java code inside a JSP page is more script-like because it doesn't require Java class and package definitions. As you will see, the Java code inside JSP is added to methods of a Java Servlet that are generated the first time the JSP is requested. Of course, JScript, VBScript, and Java are all object oriented to some degree, or maybe to avoid getting into a political argument with those of you would dispute this claim I should refer to them as 'Quasi-Object-Oriented.' Whatever we choose to call them, we can at least agree that the scripting languages used by JSP and ASP are all provided with a set of pre-established objects by the Web server that they use to generate a dynamic Web page. 

The following table lists some of the pre-established (instantiated, for the purist) objects that are available in both ASP and JSP. 
ASP JSP Definition 
Request request Access to request information. This includes such items as input/form parameters, HTTP request header information, etc. 
Response response Access to response information and construction. This includes output MIME type and other HTTP response headers as well as the output stream itself. 
Session session Access to session information. 
Application application Access to application information. 
Response.Write out Access to the response output stream. JSP provides a convenience object for direct output to this stream, whereas ASP uses a Response object method. 

Note that JSP is Java, so it is case sensitive. But capitalization doesn't matter in VBScript, so if you stick to lowercase, there really isn't any difference in the names. 

These are the main objects we have to work with when creating dynamic content in either ASP or JSP, so it's a good idea to become familiar with their methods. I'll use some of them in the examples that follow, but I can't go into every method available within the limits of this article. 

As I mentioned earlier, both ASP and JSP support a similar way of delimiting scripting from content on a page. <% and %> are used to set of sections of script, '<%=' and '%>' are used to return a value within content, and <%@ and %> are used to delimit page directives. Here is a brief example using both ASP and JSP: 


:)