Search in
Ask a Question
Balmukund Tiwari
Experienced Maths & Physics Mentor with 5+ years, B Tech graduate.
Ask a Question
Balmukund Tiwari
Experienced Maths & Physics Mentor with 5+ years, B Tech graduate.
| Applet | Servlet | |
|---|---|---|
| Runs on | Client side (browser) | Server side (web server/container) |
| Purpose | GUI/interactive content in web pages | Handle requests, generate dynamic responses |
| Needs | Browser/JVM plugin | Servlet container (e.g., Tomcat) |
| Main class | java.applet.Applet / JApplet | HttpServlet |
| Has GUI | Yes | No (outputs HTML/data) |
| Lifecycle | init, start, stop, destroy | init, service, destroy |
| Security | Restricted sandbox | Runs with server’s permissions |
| Status | Deprecated (removed from modern browsers) | Still widely used |
Ask a Question
Balmukund Tiwari
Experienced Maths & Physics Mentor with 5+ years, B Tech graduate.
No. Servlet containers are still the foundation of most Java web apps.
jakarta.* namespace). Ask a Question
Balmukund Tiwari
Experienced Maths & Physics Mentor with 5+ years, B Tech graduate.
No, but you rarely write them directly anymore.
Ask a Question
Balmukund Tiwari
Experienced Maths & Physics Mentor with 5+ years, B Tech graduate.
1. System properties and environment variables
<%= System.getProperty("os.name") %>
<%= System.getenv("JAVA_HOME") %> 2. Files on the server
<%
String path = application.getRealPath("/data/info.txt");
BufferedReader br = new BufferedReader(new FileReader(path));
%> 3. Running an OS command (rarely advisable)
<% Process p = Runtime.getRuntime().exec("hostname"); %> Ask a Question
Balmukund Tiwari
Experienced Maths & Physics Mentor with 5+ years, B Tech graduate.
@WebServlet("/certificate")
public class CertificateServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String id = req.getParameter("id");
try (Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/mydb", "user", "pass");
PreparedStatement ps = con.prepareStatement(
"SELECT student_name, course, issue_date, grade FROM certificates WHERE id = ?")) {
ps.setInt(1, Integer.parseInt(id));
ResultSet rs = ps.executeQuery();
if (rs.next()) {
req.setAttribute("name", rs.getString("student_name"));
req.setAttribute("course", rs.getString("course"));
req.setAttribute("date", rs.getDate("issue_date"));
req.setAttribute("grade", rs.getString("grade"));
req.getRequestDispatcher("certificate.jsp").forward(req, res);
} else {
res.sendError(404, "Certificate not found");
}
} catch (Exception e) {
throw new ServletException(e);
}
}
}
Ask a Question
Balmukund Tiwari
Experienced Maths & Physics Mentor with 5+ years, B Tech graduate.
JSP is Java’s server-side view layer. It generates HTML dynamically.
<% %>). Use JSTL and EL, and keep logic in servlets or classes. Ask a Question
Balmukund Tiwari
Experienced Maths & Physics Mentor with 5+ years, B Tech graduate.
Yes, but not within a single browser session.
JSESSIONID cookie, so the same user can have several sessions at once. This is automatic.HttpSession per web app, because they share the cookie.session.setAttribute("cart_" + tabId, cart).Map<String, List<HttpSession>> and update it with an HttpSessionListener or HttpSessionBindingListener.invalidate(). Ask a Question
Balmukund Tiwari
Experienced Maths & Physics Mentor with 5+ years, B Tech graduate.
<% response.sendRedirect("page2.jsp"); %> <jsp:forward page="page2.jsp" /> <a href="page2.jsp">Go</a>Call either before any output, and add return; after it.
Ask a Question
Harsh Bisht
Most JavaScript framework names have a simple idea behind them:
Overview
Questions 50.1 k
Ask a Question
The best tutors for IT Courses Classes are on UrbanPro
The best Tutors for IT Courses Classes are on UrbanPro