码迷,mamicode.com
首页 > Web开发 > 详细

JSP简介

时间:2015-05-31 12:26:05      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:java   j2ee   

1、JSP简介
    JSP全名为Java Server Pages,中文名叫java服务器页面,其根本是一个简化的Servlet设计它是在传统的网页HTML(标准通用标记语言的子集)文件(*.htm,*.html)中插入Java程序段(Scriptlet)和JSP标记(tag),从而形成JSP文件,后缀名为(*.jsp)。 用JSP开发的Web应用是跨平台的,既能在Linux下运行,也能在其他操作系统上运行。
        JSP将网页逻辑与网页设计的显示分离,支持可重用的基于组件的设计,使基于Web的应用程序的开发变得迅速和容易。 JSP(JavaServer Pages)是一种动态页面技术,它的主要目的是将表示逻辑从Servlet中分离出来。
        说的简单点就是界面显示(HTML)和服务端(Servlet)放到一起了。

2、JSP应用(JSP页面:user_add.jsp)
    <!-- JSP标志 -->  
<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>

<!-- 引入命名空间 -->  
<%@ page import="com.bjpowernode.drp.sysmgr.domain.*" %>
<%@ page import="com.bjpowernode.drp.sysmgr.manager.*" %>
<!-- 服务器端代码 -->  
<%
     //设置字符集,防止保存到数据库中出现乱码情况
    request.setCharacterEncoding("GB18030");

    String command=request.getParameter("command");
    if ("add".equals(command)){
        //获取提交表单的数据,并将其设置到User实体中
        User user=new User();
        user.setUserId(request.getParameter("userId"));
        user.setUserName(request.getParameter("userName"));
        user.setPassword(request.getParameter("password"));
        user.setContactTel(request.getParameter("contactTel"));
        user.setEmail(request.getParameter("email"));
        
         //调用后台用户管理类,完成用户添加
        UserManager.getInstance().addUser(user);
        out.println("添加用户成功!");
    }
 %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
        <title>添加用户</title>
        <link rel="stylesheet" href="../style/drp.css">
        <script src="../script/client_validate.js"></script>
        <script type="text/javascript">
    
    function addUser() {
        //form表单提交(提交到自身JSP页面,在服务端进行接收)
        with (document.getElementById("userForm")){
            action="user_add.jsp";
            method="post";
            submit();
        }
        }

</script>
    </head>
    <body class="body1" onload="init()">
        <form name="userForm" target="_self" id="userForm">
            <input type="hidden" name="command" value="add">
            <div align="center">
                <table width="95%" border="0" cellspacing="0" cellpadding="0"
                    height="25">
                    <tr>
                        <td width="522" class="p1" height="25" nowrap>
                            <img src="../images/mark_arrow_03.gif" width="14" height="14">
                            <b>系统管理>>用户维护>>添加</b>
                        </td>
                    </tr>
                </table>
                <hr width="97%" align="center" size=0>
                <table width="95%" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td width="22%" height="29">
                            <div align="right">
                                <font color="#FF0000">*</font>用户代码: 
                            </div>
                        </td>
                        <td width="78%">
                            <input name="userId" type="text" class="text1" id="userId"
                                size="10" maxlength="10" onkeypress="userIdOnkeypress()">
                        </td>
                    </tr>
                    <tr>
                        <td height="26">
                            <div align="right">
                                <font color="#FF0000">*</font>用户名称: 
                            </div>
                        </td>
                        <td>
                            <input name="userName" type="text" class="text1" id="userName"
                                size="20" maxlength="20">
                        </td>
                    </tr>
                    <tr>
                        <td height="26">
                            <div align="right">
                                <font color="#FF0000">*</font>密码: 
                            </div>
                        </td>
                        <td>
                            <label>
                                <input name="password" type="password" class="text1"
                                    id="password" size="20" maxlength="20">
                            </label>
                        </td>
                    </tr>
                    <tr>
                        <td height="26">
                            <div align="right">
                                联系电话: 
                            </div>
                        </td>
                        <td>
                            <input name="contactTel" type="text" class="text1"
                                id="contactTel" size="20" maxlength="20">
                        </td>
                    </tr>
                    <tr>
                        <td height="26">
                            <div align="right">
                                email: 
                            </div>
                        </td>
                        <td>
                            <input name="email" type="text" class="text1" id="email"
                                size="20" maxlength="20">
                        </td>
                    </tr>
                </table>
                <hr width="97%" align="center" size=0>
                <div align="center">
                    <input name="btnAdd" class="button1" type="button" id="btnAdd"
                        value="添加" onClick="addUser()">
                        
                    <input name="btnBack" class="button1" type="button" id="btnBack"
                        value="返回" onClick="goBack()" />
                </div>
            </div>
        </form>
    </body>
</html>
3、JSP总结
    目前就对JSP的认识:其就是一个综合的页面,集HTML客户端代码和Servlet端服务于一身的综合页面,虽然其功能强大了很多,但是其要管理的东西就变多了,因而也变得复杂了。如当修改服务端还得修改此页面。因为此JSP页面是为用户提供操作的,根据分层原则,还是将其单独出来,只需要满足页面显示即可,将业务逻辑拿出来放到别的地方,更便于管理和扩展。


JSP简介

标签:java   j2ee   

原文地址:http://blog.csdn.net/u010927139/article/details/46287577

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!