JSP (1)
2015-06-07 05:06
671 查看
1. HTTP方法
GET : 像特定的资源发出请求
POST: 向指定资源提交数据进行处理请求
2 用JSP输出hello
用myeclipse创建java web项目,在如图:
在Hello中添加代码:
编译指令
Page指令
用于定义当前jsp程序的全局属性,位于最上方
<%@ page language="java" // 声明当前jsp使用的脚本语言的种类
contentType="text/html; charset=ISO-8859-1" // 服务器生成网页的编码
pageEncoding="ISO-8859-1" // 用于设置jsp本身的编码
%>
import用于导入java类
<%@ page import = "java.util.ArrayList" %>
<%@ page import ="java.util.LinkedList" %>
include 指令
将一个外部文件包含到当前的jsp程序中
动作指令
forward指令
是一个重定向指令,forward下面的代码不会被执行
<jsp:forward page="myinclude.jsp"></jsp:forward>
传递参数:
myinclude.jsp中:
include指令: 动态包含指令
动态:jsp
静态:html
useBean指令
添加类
添加代码:
新建register.jsp
新建doregister.jsp
GET : 像特定的资源发出请求
POST: 向指定资源提交数据进行处理请求
2 用JSP输出hello
用myeclipse创建java web项目,在如图:
在Hello中添加代码:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <!--html <%=new java.util.Date().toString() %> --> <%--JSP <%=new java.util.Date().toString() %> --%> <%! String str = "Hello"; // 全局变量 %> <% out.println(str); %> </body> </html>
编译指令
Page指令
用于定义当前jsp程序的全局属性,位于最上方
<%@ page language="java" // 声明当前jsp使用的脚本语言的种类
contentType="text/html; charset=ISO-8859-1" // 服务器生成网页的编码
pageEncoding="ISO-8859-1" // 用于设置jsp本身的编码
%>
import用于导入java类
<%@ page import = "java.util.ArrayList" %>
<%@ page import ="java.util.LinkedList" %>
include 指令
将一个外部文件包含到当前的jsp程序中
<body> <%@ include file="header.html" %> <br/> <%@ include file="Hello.jsp" %> </body>
动作指令
forward指令
是一个重定向指令,forward下面的代码不会被执行
<jsp:forward page="myinclude.jsp"></jsp:forward>
传递参数:
<jsp:forward page="myinclude.jsp"> <jsp:param value="thystar" name="userName"/> <jsp:param value="123" name="password"/> </jsp:forward>
myinclude.jsp中:
<body> <% String userName = request.getParameter("userName"); String password = request.getParameter("password"); out.println(userName); out.println("</br>"); out.println(password); %> </body>
include指令: 动态包含指令
动态:jsp
静态:html
<jsp:include page="myinclude.jsp"> <jsp:param value="red" name="bjcolor"/> </jsp:include>myinclude.jsp中
<body bgcolor="<%=request.getParameter("bjcolor")%>"> </body>
useBean指令
添加类
添加代码:
package com.jike.entity; import java.io.Serializable; public class UserEntity implements Serializable { /** * */ private static final long serialVersionUID = 1L; private String userName; private String password; public UserEntity() { super(); } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
新建register.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>录入注册信息</title> </head> <body> <form action="doregister.jsp" method="post"> 用户名: <input type="text" name="userName"/> 密码:<input type="password" name="password"/> <input type="submit" value="提交"/> </form> </body> </html>
新建doregister.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>提交的内容</title> </head> <body> <jsp:useBean id="user" class="com.jike.entity.UserEntity"></jsp:useBean> <jsp:setProperty property="userName" name="user"/> <jsp:setProperty property="password" name="user"/> <jsp:getProperty property="userName" name="user"/> <jsp:getProperty property="password" name="user"/> </body> </html>
相关文章推荐
- java对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- GUI - Web前端开发框架
- 介绍一款信息管理系统的开源框架---jeecg
- Extjs4.0 最新最全视频教程
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- PropertyChangeListener简单理解
- 插入排序
- 冒泡排序
- 堆排序