如何将JSP页面中进行数据传输到数据库?

1、没有数据库,假设在新的jsp页面中显示 模拟 数据库;

2、将a.jsp中的数据 传入到 b.jsp中;

过程:

 

1. browser显示的前端页面 a.jsp

<body>
   <form action=”aa.jsp” method=”post”>
    <table class=”tb” border=”0″ cellspacing=”5″ cellpadding=”0″ align=”center”>
<tr><td align=”center” colspan=”2″ style=”text-align:center;” class=”text_tabledetail2″>用户注册</td></tr>
<tr>
<td class=”text_tabledetail2″>用户名</td>
<td><input type=”text” name=”username” value=””/></td>
</tr>
<tr>
<td class=”text_tabledetail2″>密码</td>
<td><input type=”password” name=”password” value=””/></td>
</tr>
<tr>
<td class=”text_tabledetail2″>确认密码</td>
<td><input type=”password” name=”con_password” value=””/></td>
</tr>
<tr>
<td class=”text_tabledetail2″>email</td>
<td><input type=”text” name=”email” value=””/></td>
</tr>
<tr>
<td class=”text_tabledetail2″>爱好</td>
<td>
<input type=”checkbox” name=”hobby” value=”swim” />游泳<br/>
<input type=”checkbox” name=”hobby” value=”read” />阅读<br/>
<input type=”checkbox” name=”hobby” value=”climb” />爬山<br/>
<input type=”checkbox” name=”hobby” value=”travel” />旅游<br/>
</td>
</tr>
<tr>
<td style=”text-align:center;” colspan=”2″>
<button type=”submit” class=”page-btn” name=”save”>注册</button>
<button type=”button” class=”page-btn” name=”return” οnclick=”javascript:location.href='<%=request.getContextPath() %>/index.jsp'”>返回</button>
</td>
</tr>
</table>
   </form>

 

</body>

+++++++++++++++++++

2、 传入到模拟数据库b.jsp

  <body>
         <%
          String username=request.getParameter(“username”);
          String pwd=request.getParameter(“password”);
          String email=request.getParameter(“email”);
          String[] hobbys=request.getParameterValues(“hobby”);
          %>
          用户名:
          <%
          if(username!=null && !username.equals(“”)){  
           %>
           <%=username%>
           <%}else{
            out.print(“用户名为空”);
           
           } %>
           <br/>
           密码:<%=pwd %> <br/>
    Email:<%=email %><br/>
    爱好:<br/>
    <%
     if(hobbys!=null && hobbys.length!=0){
             for(String hobby : hobbys){
                out.println(hobby+”<br/>”);
             }
         
         }else{
          out.println(“请选择爱好”);
         }
    
     %>
        
    
  </body>
</html>

    原文作者:高旭t-t
    原文地址: https://blog.csdn.net/qq_42746098/article/details/82635219
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞