createstudent.jsp
来自「100多M的J2EE培训内容」· JSP 代码 · 共 66 行
JSP
66 行
<%@ page contentType="text/html; charset=GBK" %>
<%@ page language="java" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="cmpsample.*" %>
<html>
<head><title>Chapter 11 CMP 2.0 Sample Example </title></head>
<body bgcolor="white">
<center>
<h2>Chapter 11 CMP 2.0 StudentJB - create a Student entity</h2>
Create a new Student:
<p>
<form method="post" action="/WebApp/createStudent.jsp">
<table border=10>
<tr>
<td>Student ID: </td>
<td><input type="text" name="id" size="11" value=""></td>
</tr>
<tr>
<td>First Name: </td>
<td><input type="text" name="firstName" size="25" value=""></td>
</tr>
<tr>
<td>Last Name: </td>
<td><input type="text" name="lastName" size="25" value=""></td>
</tr>
</table>
<p>
<input type="submit" name="submit" value="Submit">
<p>
</form>
<%
String id = request.getParameter("id");
String firstName = request.getParameter("firstName");
String lastName = request.getParameter("lastName");
if (id != null && !"".equals(id)) {
try {
InitialContext ic = new InitialContext();
Object o = ic.lookup("Student");
StudentHome home = (StudentHome) o;
Student student = home.create(id, firstName, lastName);
%>
New Student:
<%=student.getLastname()%>,
<%=student.getFirstname()%>
<br>
created.
</p>
<a href = "/WebApp/searchStudent.jsp">SEARCH</a></p>
<%
} catch(Exception e) {
e.printStackTrace();
out.println("Create new Student FAILED : " + e.toString());
}
}
%>
<hr>
[<a href="/WebApp/index.html">HOME</a>]
</center>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?