createStudent.jsp
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:2k
源码类别:
Java编程
开发平台:
Java
- <%@ 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>