JavaBean의 간단한 응용 프로그램 JSP 페이지

8159 단어
MyEclipse에서는 양식을 Dreamweaver로 디자인할 수 있습니다.'표'에 div를 삽입한 다음div에 표를 디자인해야'표의 단추 기능을 제출해야 전체 표의 내용을 얻을 수 있다는 것을 기억하세요.
eg:
Person 클래스를 만들려면 다음과 같이 하십시오.
package org.caiduping.org;

public class Person {
    private String name;
    private int age;
    private String sex;
    private String add;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public String getSex() {
        return sex;
    }
    public void setSex(String sex) {
        this.sex = sex;
    }
    public String getAdd() {
        return add;
    }
    public void setAdd(String add) {
        this.add = add;
    }
}

index.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
  </head>
  
  <body>
  <form action="reg.jsp" method="post">
 <table width="500" border="0" height="255">
  <tr>
    <td colspan="2"><div align="center">      </div></td>
  </tr>
  <tr>
    <td>  :</td>
    <td>   
        <input name="name" type="text" id="name" />      
    </td>
  </tr>
  <tr>
    <td>  :</td>
    <td>
        <input name="age" type="text" id="age" /> 
    </td>
  </tr>
  <tr>
    <td>  :</td>
    <td>
      <input name="sex" type="text" id="sex" />    
    </td>
  </tr>
  <tr>
    <td>  :</td>
    <td>
        <input name="add" type="text" id="add" /> 
    </td>
  </tr>
  <tr>
    <td colspan="2">    
        <input type="submit" name="Submit" value="  " />
        </td>
  </tr>
</table>
</form>
  </body>
</html>

reg를 다시 생성합니다.jsp 페이지: (index에서reg 페이지로 이동)
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'MyJsp.jsp' starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>
  
  <body>
   <jsp:useBean id="person" class="org.caiduping.org.Person" scope="page">
      <jsp:setProperty name="person" property="*"/>
   </jsp:useBean>

   <table width="500" border="0">
  <tr>
    <td>  :</td>
    <td><jsp:getProperty property="name" name="person"/>
    </td>
  </tr>
  <tr>
    <td>  :</td>
    <td><jsp:getProperty property="age" name="person"/>
    </td>
  </tr>
  <tr>
    <td>  :</td>
    <td><jsp:getProperty property="sex" name="person"/>
    </td>
  </tr>
  <tr>
    <td>  :</td>
    <td><jsp:getProperty property="add" name="person"/>
    </td>
  </tr>
</table>
  </body>
</html>

좋은 웹페이지 즐겨찾기