1 . 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: 


:)


Leave a Comment

Name  
  Email   
Message
1 . Apache tomcat <error-page> tag in conf/web.xml not rendering an error page?
 

Answer :

using error-code instead of exception-type

<error-page>
    <error-code>403</error-code>
    <location>/error.jsp</location>
</error-page>

2 . Passing an ArrayList from Struts1.3 action to appropriate JSP?
 

Answer :

Remove attribute redirect="true" from the forward config it makes lose of attributes required for jsp redirected.

How can you be assure about action class if it doesn' t make sense to jsp? The values are evaluated by the EL expressions and rendered by Jstl tags, so you have to make sure they are accessible in the scope of jsp. Forwarding to jsp saves the variables to request scope then you can read them in the for each tag.


3 . Could not get values from request.getParameter Java JSP?
 

Answer :

disabled elements in a form will not be submitted. You may have to use readonly.


4 . I am trying to print result on same page using ajax query in java servlet form [duplicate]?
 

Answer :

You never actually call the post function with your ajax code or stop the form from loading the register page.

If you called the post function then checked your console you might see something like Uncaught TypeError: document.getElementByName is not a function, because the function is getElementsByName(notice the s) and it returns a list of elements which needs to be taken into account.
Since you're using jQuery you could just use .serialize() on the form to get its field data.

$(document).ready(function(){

    $('form').submit(function()
    {
        $.ajax
        ({
            type: 'post',
            url: 'RegisterServlet.java',
            data: $(this).serialize(),
            success: function (response)
            {
                document.getElementsByName("insert")[0].innerHTML="Form Successfully Registerd";
            }
        }); 
        return false;
    });
});

5 . Thymeleaf list within list input?
 

Answer :

Template: Create unique "modal" for each job. (work-list.html)

<form method="post" action="#" th:action="@{/work-list}" th:object="${workHistoryDetails}">
 <table>
  <thead>
   <tr>
    <th>
      <button type="submit" name="addRow" th:text="'Add Row'">Add row</button>
    </th>
   </tr>
  </thead>
  <tbody>
   <tr id='addr_work0' th:each="workRow, rowStat : *{jobs}">
    <td th:text="${rowStat.index + 1}"></td>
      <td><input type="text" 
                placeholder='Company Name'  class="form-control" th:field="*{jobs[__${rowStat.index}__].companyName}"/></td>
      <td><input type="text" 
                placeholder='Company city' class="form-control" th:field="*{jobs[__${rowStat.index}__].city}"/></td>


      <td><button type="button" class="btn btn-primary" data-toggle="modal" th:attr="data-target='#myModal'+${rowStat.index}" >Open modal</button></td>

      <!-- The Modal -->
      <div class="modal fade" th:id="'myModal'+${rowStat.index}">
       <div class="modal-dialog">
        <div class="modal-content">

         <!-- Modal Header -->
         <div class="modal-header">
           <h4 class="modal-title">Modal Heading</h4>
           <button type="button" class="close" data-dismiss="modal">&times;</button>
         </div>

         <!-- Modal body -->
         <div class="modal-body">
           <input type="text"
                placeholder='Company Name'  class="form-control" th:field="*{jobs[__${rowStat.index}__].workDoneSentences[0]}"/>
           <input type="text" 
                placeholder='Company city' class="form-control" th:field="*{jobs[__${rowStat.index}__].workDoneSentences[1]}"/>
         </div>

         <!-- Modal footer -->
         <div class="modal-footer">
           <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
         </div>

        </div>
       </div>
      </div>
    </tr>
   </tbody>
  </table>
 <input type="submit" name="submit" value="Add" class="btn btn-danger" />
</form> 

Controller:

@ModelAttribute("workHistoryDetails")
public WorkHistory populateWorkHistories() {
    return this.workHistory.getAllHistoryDetail();
}

@Autowired
WorkHistoryService workHistory;

@GetMapping("/work-list")
public String greeting(final WorkHistory workHistoryDetails) {
    return "work-list";
}

@RequestMapping(value="/work-list",method=RequestMethod.POST)
public String create(final WorkHistory workHistoryDetails) {

   this.workHistory.setJobs(workHistoryDetails);
   return "work-list";
}

// for adding new row job to jobs list
@RequestMapping(value="/work-list", params={"addRow"})
public String addRow(final WorkHistory workHistoryDetails, Model model) {

    Jobs jobRow = new Jobs("","",new ArrayList<>());
    workHistoryDetails.getJobs().add(jobRow);
    model.addAttribute("workHistoryDetails", workHistoryDetails);
    return "work-list";
}

Service: Just for the sake of testing:

@Service
public class WorkHistoryService {

    static WorkHistory workHistoryDetails =new WorkHistory();
    static{
        List<String> workDones = new ArrayList<>();
        workDones.add("angular");
        workDones.add("description");
        List<String> workDones1 = new ArrayList<>();
        workDones1.add("java,c++");
        workDones1.add("description also");

        Jobs job1 = new Jobs("Twitter", "USA",workDones); 
        Jobs job2 = new Jobs("Microsoft", "USA",workDones1);
        List<Jobs> jobList = new ArrayList<>();
        jobList.add(job1);
        jobList.add(job2);
        workHistoryDetails.setJobs(jobList);
    }

    public WorkHistory getAllHistoryDetail(){

        return workHistoryDetails;
    }

    public void setJobs(WorkHistory workHistory){
        workHistoryDetails.getJobs().clear();
        List<Jobs> jobs = workHistory.getJobs();
        for (Jobs job : jobs) {
            workHistoryDetails.getJobs().add(job);
        }
    }
}

Jobs domain:

public class Jobs {
   private String companyName;
   private String city;
   private List<String> workDoneSentences;
    //default constructor important!   
    public Jobs() {
    super();
    }
   //setter getter
}

I hope it helps you.



6 . Java EE .jsp file can't be accessed through localhost?
 

Answer :

I had the same issue, it was because of Wildfly 11. I downgraded it to Wildfly 10.1 and it started working!


7 . Pass value Bean to Class then Class to JSP?
 

Answer :

Set the value in ServletContext in your bean class:

 @Autowired
    private ServletContext servletContext;

    private String a;
    public void setA(String a) {
       servletContext.setAttribute("a",a);
    }
Get this value in JSP using :

<%
String a=(String)getServletContext().getAttribute("a");
%>


8 . Text Area dynamically created and then gone within a second?
 

Answer :
I have tried your code and discovered that the problem is coming from your form tag if you remove the form tag it will work just fine.

<html>
    <head>
    </head>
    <body>
    <div class="container">

       <div class="row">

         <div class="col-name">
          <label for="section">Section</label>
         </div>

          <div class="col-value">
           <input type="text" id="section">
          </div>
        </div>

        <div class="row">

         <div class="col-name">
          <label for="assignmentname">Assignment Name</label>
         </div>

          <div class="col-value">
           <input type="text" id="assignmentname">
          </div>
        </div>

        <div class="row">

         <div class="col-name">
          <label for="questionnumber">Number Of Questions</label>
         </div>

          <div class="col-value">
           <input type="text" id="question_number" max="10" min="1"/>
          </div>

          <div class="col-value">
          <button onclick="generate()">Generate Assignment</button>
          </div>
        </div>

        <div id="content">

        </div>

        </div>


       <script>
     function generate(){
    var x = document.getElementById("question_number").value;
    var content = document.getElementById("content");
    var pa= new Array();
    var box = new Array();
    while(content.hasChildNodes()){
        content.removeChild(content.lastChild);
    }

    var i=0;
    while(i<x){
        pa[i]=document.createElement("p");
        var box =document.createElement("textarea");
        box.style.minHeight="100px";
        box.style.minWidth="300px";
        box.style.animation="moveToPos 5s 1";
        box.style.animationFillMode="forwards";
        pa[i].appendChild(box);
        content.appendChild(pa[i]);
        i++;
      }
}
       </script>

     </body>
    </html>

9 . List not visible on when sent from Spring controller to JSP?
 

Answer :

<c:if test="${not empty lists}">

To:

<c:if test="${not empty mediaList}">

10 . Problem with while( rs.next()) in jsp?

Answer :

  Well, yeah. It's hard to tell without the indenting, but it looks like all your code paths redirect to another page during the first rs loop. I don't know the particulars of JSP, but it probably stops execution once it sees that redirect.



11 . How to embed jsp coding into javascript method?how to assing javascript variable in jsp session in javascriptm?

Answer :

You might NOT remember, but English language has some grammar rules AND punctuation... Using that helps readers to understand what YOU are trying to say... 

JSP - server side scripting technology, it runs on web server and generates HTML/JavaScript that gets sent to client (browser), ALL generated content gets sent to client (browser) AFTER it FINISHED it's job... 
JavaScript - client side scripting language, it runs on client (browser) AFTER the page is received by the client (browser)... 

The only way to send values from JSP to JavaScript is to generate some JavaScript statements in JSP (assign a JavaScript value...) 
The only way to send values from JavaScript to JSP is to request something from web server (AJAX or simple GET or POST requests)...


12 . How do i implement pop ups using JSP?

Answer :

You r to do it in javascript. If u want to use it in ur JSP page U can use STRUTS tags to include ur javascript code. 
STRUTS has the following tag attributes 
onmousedown 
onmousemove 
onmouseout 
onmouseover 
onmouseup 


13 . What is Best Web Language for Website designing & as well as CGI Scripting Perl/Java/Php/ HTML/XML/JSP etc ???

Answer :

 You obviously have to use HTML, but as a server side language, I suggest PHP, it is lightweight and you can do nice database stuff with it. 

I am a bit biased as I have not used Perl or JSP, but have used the others, and of which I find PHP works the best. 

But first decide on your needs, and then do research on the benefits of each and choose according to your requirements.


14 . Difference between java script an jsp?

Answer :

 Java is a programming language and it requires compilation before it can be executed where is JSP(Java Server Pages) is server side scripting technology which don't need compilation. t is being interpreted at the runtime!


15 . How to connect jsp with oracle?

Answer :

  It is very easy to connect to oracle database from a JSP though JSP are used to cater the view part of the application. 
You can use classes12.jar file to connect to oracle database. 
put the following code in the scriplet and ensure that you close the connection in the finally block :) 

-Surya Rao.

Source(s)://place the code in the JSP 
<% 
//register driver 
DriverManager.registerDriver("oracle.j... 
//get the database connection 
Connection con = 
DriverManager.getConnection ("jdbc:oracle:thin:@<<DBServerIPaddress>... 
"<<userName>>", "<<password>>"); 
// Create statement 
Statement stmt = con.createStatement (); 
ResultSet rs = stmt.executeQuery ("select * from Emp"); 

// Iterar mientras haya datos. 
while (rset.next ()) 
System.out.println (rset.getString ("empNumber")); 

%>