Jsp与servlet之间页面跳转及参数传递实例(转)
原网址:http://blog.csdn.net/ssy_shandong/article/details/9328985
1.从一个jsp页面跳转到另一个jsp页面时的参数传递
- <%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <body>
- <form action="getinfo.jsp">
- <input type="text" name="name">
- <input type="submit" value="Enter" name="submit">
- </form>
- </body>
- </html>
getinfo.jsp页面代码如下:
- <%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <body>
- <p>获取文本框提交的信息:
- <%
- String textContent = request.getParameter("name");
- %>
- <br/>
- <%=textContent%>
- </p>获取按钮的名字:
- <%
- String buttonName = request.getParameter("submit");
- %>
- <br/>
- <%=buttonName%>
- </body>
- </html>
- <%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <body>
- <form action="session2.jsp" method="post">
- 请输入您的姓名:
- <input type="text" name="thename">
- <input type="submit" value="submit">
- </form>
- </body>
- </html>
session2.jsp通过request对象提取session1.jsp表单中的thename值,并将其保存到session对象中,session2.jsp代码如下:
- <%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <body>
- <%
- String name = request.getParameter("thename");
- session.setAttribute("thename",name);
- %>
- 您的姓名是:<%=name%>
- <p>
- <form action="session3.jsp?pwd=123456" method="post">
- 您喜欢吃什么?
- <input type="text" name="food"/>
- <p>
- <input type="submit" value="submit">
- </form>
- </body>
- </html>
session3.jsp的主要任务是显示结果,它从session对象提取thename的值并显示它,以证明在多个页面中可以通过session对象存储和维持信息,session3.jsp代码如下:
- <pre name="code" class="java"><%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <body>
- <%
- String food = request.getParameter("food");
- String name = (String)session.getAttribute("thename");
- String pwd = request.getParameter("pwd");
- %>
- 您的姓名是:<%=name%>
- <p>
- 您喜欢吃:<%=food%>
- <p>
- 您的密码是:<%=pwd%>
- </body>
- </html></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <body>
- <form action="hidden.jsp" method="post" name="form1">
- <!-- 隐藏字段,系统时间,并转换为毫秒数 -->
- <input type="hidden" name="time" value="<%=new java.util.Date()%>">
- <p>
- 请输入您的姓名:<input type="text" name="name">
- </p>
- <input type="submit" name="submit" value="submit">
- </form>
- </body>
- </html>
显示隐藏空间信息的hidden.jsp代码如下:
- <%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <body>
- <%
- String name = request.getParameter("name");
- String date = request.getParameter("time");
- %>
- <p>您的姓名是:
- <%=name %>
- </p>
- <p>提交时的系统时间为:
- <%=date %>
- </p>
- </body>
- </html>
程序运行结果如下:
- <%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <%
- int PageCount = 15;
- %>
- <html>
- <body>
- <table>
- <tr>
- <td>
- <a href=showpage.jsp?ToPage=<%=1%>>到第1页</a>
- </td>
- <td>
- <a href=showpage.jsp?ToPage=<%=PageCount%>>到最后一页</a>
- </td>
- </tr>
- </table>
- </body>
- </html>
接收显示分页showpage.jsp代码如下:
- <%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <body>
- <%
- String toPage = request.getParameter("ToPage");
- out.println("第" + toPage + "页");
- %>
- </body>
- </html>
运行结果如下:
2.jsp页面传递参数给servlet
- package com.shi.servlet;
- import java.io.IOException;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- /**
- * 本类用来获得表单请求信息,并根据请求信息转发页面
- */
- public class ForwardServlet extends HttpServlet
- {
- private static final long serialVersionUID = 1L;
- /**
- * 构造函数
- */
- public ForwardServlet()
- {
- super();
- }
- /**
- * 初始化
- */
- public void init() throws ServletException
- {}
- /**
- * doGet()方法
- */
- public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- doPost(request, response);
- }
- /**
- * doPost()方法
- */
- public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- String name = request.getParameter("name");
- String pwd = request.getParameter("pwd");
- if((name!=null && !name.equals("")) && (pwd!=null && !pwd.equals("")))
- {
- if(name.equals("mr")&&pwd.equals("123"))
- {
- request.getRequestDispatcher("success.jsp").forward(request, response);
- }
- else
- {
- request.getRequestDispatcher("error.jsp").forward(request, response);
- }
- }
- }
- /**
- * 销毁
- */
- public void destroy()
- {
- super.destroy();
- }
- }
在web.xml中配置ForwardServlet类,代码如下:
- <?xml version="1.0" encoding="GB2312"?>
- <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
- <!-- 配置servlet -->
- <servlet>
- <servlet-name>ForwardServlet</servlet-name>
- <servlet-class>com.shi.servlet.ForwardServlet</servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>ForwardServlet</servlet-name>
- <url-pattern>/forward</url-pattern>
- </servlet-mapping>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- </web-app>
新建index.jsp,其中<form>中的action属性值为Servlet类在web.xml中配置的url,提交方式为post,代码如下:
- <%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <body>
- <form action="forward" method="post">
- <table align="center">
- <tr>
- <td>用户名:</td>
- <td>
- <input type="text" name="name"/>
- </td>
- </tr>
- <tr>
- <td>密码:</td>
- <td>
- <input type="password" name="pwd"/>
- </td>
- </tr>
- <tr>
- <td colspan="2">
- <input type="submit" value="登录"/>
- </td>
- </tr>
- </table>
- </form>
- </body>
- </html>
登录成功页面success.jsp,代码如下:
- <%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <body>
- 欢迎<%=request.getParameter("name") %>,登录成功!
- </body>
- </html>
程序的运行结果图5所示:
(2)使用session对象,url,form表单传递参数
- <%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <body>
- <%
- session.setAttribute("testSession","Hello session");
- request.setAttribute("testRequest","Hello request");
- %>
- <a href="http://localhost:8080/086/jsp2servlet?hrefAction=toServlet">单击此处</a>
- <form action="jsp2servlet?action=toServlet" method="post" name="form1">
- <input type="text" name="username"/>
- <input type="submit" value="submit"/>
- </form>
- </body>
- </html>
在Jsp2Servlet中接收jsp页面中传递的参数并将其显示,代码如下:
- package com.shi.servlet;
- import java.io.IOException;
- import java.io.PrintWriter;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- public class Jsp2Servlet extends HttpServlet
- {
- /**
- * 自动生成
- */
- private static final long serialVersionUID = 1L;
- /**
- * 构造函数
- */
- public Jsp2Servlet()
- {
- super();
- }
- /**
- * 初始化
- */
- public void init()
- {}
- /**
- * doGet()
- */
- public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- doPost(request, response);
- }
- /**
- * doPost()
- */
- public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- String strSession = (String)request.getSession().getAttribute("testSession");
- String strRequest = (String)request.getAttribute("testRequest");
- String strHref = request.getParameter("hrefAction");
- String strForm = request.getParameter("action");
- String username = request.getParameter("username");
- PrintWriter out = response.getWriter();
- out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
- out.println("<html>");
- out.println("<body>");
- out.println("保存到session中的内容: " + strSession + "<br>");
- out.println("保存到request中的内容:" + strRequest + "<br>");
- out.println("超链接中传递的参数值为:" + strHref + "<br>");
- out.println("form表单中传递的action值为:" + strForm + "<br>");
- out.println("form表单内input标签中username的值: " + username + "<br>");
- out.println("</body>");
- out.println("</html>");
- }
- /**
- * 销毁
- */
- public void destroy()
- {
- super.destroy();
- }
- }
程序运行结果如图6所示:
3.从servlet到jsp页面中传递参数
- package com.shi.servlet;
- import java.io.IOException;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- public class Servlet2Jsp extends HttpServlet
- {
- /**
- * 自动生成
- */
- private static final long serialVersionUID = 1L;
- /**
- * 构造函数
- */
- public Servlet2Jsp()
- {
- super();
- }
- /**
- * 初始化
- */
- public void init()
- {}
- /**
- * doGet()
- */
- public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- doPost(request, response);
- }
- /**
- * doPost()
- */
- public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- String url = "result.jsp?first=传递第一个参数&second=传递第二个参数";
- String strRequest = "request传值";
- String strSession = "session传值";
- request.setAttribute("strRequest", strRequest);
- request.getSession().setAttribute("strSession", strSession);
- /**
- * 客户端跳转:效率低
- * session范围属性,url中的参数会传递下去,request范围属性不传递
- */
- //response.sendRedirect(url);
- /**
- * 服务器端跳转:常用,效率高
- * request范围属性,session范围属性,url中的参数会传递
- */
- request.getRequestDispatcher(url).forward(request, response);
- }
- /**
- * 销毁
- */
- public void destroy()
- {
- super.destroy();
- }
- }
- <%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <body>
- <%
- String strURL = request.getParameter("first");
- String strRequest = (String)request.getAttribute("strRequest");
- String strSession = (String)request.getSession().getAttribute("strSession");
- %>
- <p>
- URL中取得的属性值为:<%=strURL%>
- </p>
- <p>
- request中取得的属性值为:<%=strRequest%>
- </p>
- <p>
- session中取得的属性值为:<%=strSession%>
- </p>
- </body>
- </html>
程序的运行结果如图7所示:
4.从一个servlet到另一个servlet时的参数传递
- package com.shi.servlet;
- import java.io.IOException;
- import java.io.PrintWriter;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- public class ServletA extends HttpServlet
- {
- /**
- * 自动生成
- */
- private static final long serialVersionUID = 1L;
- /**
- * 构造函数
- */
- public ServletA()
- {
- super();
- }
- /**
- * 初始化
- */
- public void init()
- {}
- /**
- * doGet()
- */
- public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- doPost(request, response);
- }
- /**
- * doPost()
- */
- public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- response.setContentType("text/html");
- PrintWriter out = response.getWriter();
- String name = "hello, servlet";
- out.println("<html>");
- out.println("<body>");
- /**
- * 超链接
- */
- out.println("<a href='ServletB?name="+name+"'>this is a test</a>");
- /**
- * 表单
- */
- out.println("<form action='ServletB' method='post'>");
- out.println("用户名:");
- out.println("<input type='text' name='username'>");
- out.println("<input type='submit' vlue='提交'>");
- out.println("</form>");
- out.println("</body>");
- out.println("</html>");
- out.flush();
- }
- /**
- * 销毁
- */
- public void destroy()
- {
- super.destroy();
- }
- }
接收servlet中传递参数的代码如下:
- package com.shi.servlet;
- import java.io.IOException;
- import java.io.PrintWriter;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- public class ServletB extends HttpServlet
- {
- /**
- * 自动生成
- */
- private static final long serialVersionUID = 1L;
- /**
- * 构造函数
- */
- public ServletB()
- {
- super();
- }
- /**
- * 初始化
- */
- public void init()
- {}
- /**
- * doGet()
- */
- public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- doPost(request, response);
- }
- /**
- * doPost()
- */
- public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- String name = request.getParameter("name");
- String username = request.getParameter("username");
- response.setContentType("text/html;charset=gb2312");
- PrintWriter out = response.getWriter();
- out.println("<html>");
- out.println("<body>");
- out.println("超链接传递的参数值为:" + name);
- out.println("form表单中提交的用户名为:" + username);
- out.println("</body>");
- out.println("</html>");
- out.flush();
- }
- /**
- * 销毁
- */
- public void destroy()
- {
- super.destroy();
- }
- }
程序运行结果如图8所示:
(2)使用setAttribute()和getAttribute()方法传递参数
- package com.shi.servlet;
- import java.io.IOException;
- import java.io.PrintWriter;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- public class ServletA extends HttpServlet
- {
- /**
- * 自动生成
- */
- private static final long serialVersionUID = 1L;
- /**
- * 构造函数
- */
- public ServletA()
- {
- super();
- }
- /**
- * 初始化
- */
- public void init()
- {}
- /**
- * doGet()
- */
- public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- doPost(request, response);
- }
- /**
- * doPost()
- */
- public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- /**
- * setAttribute()和getAttribute()
- */
- String data = "This is a test, we need more test for this";
- request.setAttribute("strAtt", data);
- request.getRequestDispatcher("/ServletB").forward(request, response);
- }
- /**
- * 销毁
- */
- public void destroy()
- {
- super.destroy();
- }
- }
获取参数的ServletB代码如下:
- package com.shi.servlet;
- import java.io.IOException;
- import java.io.PrintWriter;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- public class ServletB extends HttpServlet
- {
- /**
- * 自动生成
- */
- private static final long serialVersionUID = 1L;
- /**
- * 构造函数
- */
- public ServletB()
- {
- super();
- }
- /**
- * 初始化
- */
- public void init()
- {}
- /**
- * doGet()
- */
- public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- doPost(request, response);
- }
- /**
- * doPost()
- */
- public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- String strAtt = (String)request.getAttribute("strAtt");
- response.setContentType("text/html;charset=gb2312");
- PrintWriter out = response.getWriter();
- out.println("<html>");
- out.println("<body>");
- out.println("getAttribute()得到的数据值为:" + strAtt);
- out.println("</body>");
- out.println("</html>");
- out.flush();
- }
- /**
- * 销毁
- */
- public void destroy()
- {
- super.destroy();
- }
- }
程序的运行结果如图9所示:
- <%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <link rel="stylesheet" type="text/css" href="css/style.css">
- </head>
- <body>
- <jsp:forward page="UpdateServlet">
- <jsp:param value="list" name="action" />
- </jsp:forward>
- </body>
- </html>
程序运行结果如图10所示:
- <%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <body>
- <%
- response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
- String newLocn = "2.jsp";
- response.setHeader("Location",newLocn);
- %>
- </body>
- </html>
转向页2.jsp代码如下:
- <%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <body>
- 从1.jsp跳转至此页
- </body>
- </html>
程序运行结果如图11所示:
- <meta http-equiv="refresh" content="5; url=target.jsp"
含义是:在5秒后正在浏览的页面将会自动变为target.jsp页。代码中5为刷新的延迟时间,以秒为单位。target.jsp为你想转向的目标页,若为本页则自动刷新本页。
- <%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <body>
- <%
- String content = "5; url=5_2.jsp";
- response.setHeader("REFRESH",content);
- %>
- 5_1.jsp页面,5秒后转向5_2.jsp页面。
- </body>
- </html>
转向页5_2.jsp代码如下:
- <%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <body>
- 从5_1.jsp转到的页面
- </body>
- </html>
程序运行结果如下:
Jsp与servlet之间页面跳转及参数传递实例(转)的更多相关文章
- 【转】(超详细)jsp与servlet之间页面跳转及参数传递实例
初步学习JavaEE,对其中jsp与Servlet之间的传值没弄清楚,查看网上资料,发现一篇超详细的文章,收获大大,特此记录下来.具体链接:http://blog.csdn.net/ssy_shand ...
- jsp与servlet之间的参数传递【转】
JSP与 servlet之间的传值有两种情况:JSP -> servlet, servlet -> JSP. 通过对象 request和 session (不考虑 application) ...
- Servlet——提交表单信息,Servlet之间的跳转
HTML表单标签:<form></form> 属性: actoion: 提交到的地址,默认为当前页面 method: 表单提交方式 有get和post两种方式,默认为get ...
- JSP与Servlet之间传值
Jsp与Servlet之间的传值有两种,一种是Jsp传值给Sevlet,另一种是Servlet传值给Jsp:使用request.response对象完成传值,具体实现如下: 1.JSP传值给Servl ...
- JSP与Servlet之间传值的一般方法,适合新手做练习
#JSP与Servlet之间传值 Jsp与Servlet之间的传值有两种,一种是Jsp传值给Sevlet,另一种是Servlet传值给Jsp:使用request.response对象完成传值,具体实现 ...
- Web jsp开发学习——实现页面跳转和传参
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletExcepti ...
- Java开发之Servlet之间的跳转
一.转向(Forward) 1.要点说明 转向是通过RequestDispatcher对象的forward()方法来实现的.RequestDispatcher可以通过HttpServletReques ...
- js、JSP、servlet之间的传递小结
@ JS 与 JSP :JSP无法直接获取JS的值,只能通过隐藏表单或者dom节点设置. JSP中设置隐藏表单input,或者设置任意一个隐藏或者不隐藏的节点比如div, 而JS就通过document ...
- JSP和servlet之间的传值(总结的很全面)
转自:http://blog.csdn.net/ssy_shandong/article/details/9328985 1.从一个jsp页面跳转到另一个jsp页面时的参数传递 (1)使用re ...
随机推荐
- delphi 调用 webservice (.NET C#版)
uses XMLIntf, XMLDoc; XML to XTR文件转换 .File-->open打开你要分析的XML文件 .在左边选择你要分析的接点,双击加到中间的转换列表中 .Create- ...
- JavaScript获取HTML页面源代码
来自:http://www.cnblogs.com/luckbird/archive/2008/02/01/1061048.html <a href="javascript:gets( ...
- 配置MySQL主从双向同步
原文地址:http://www.cnblogs.com/zhongshengzhen/ 原主数据库:192.168.137.33 原从数据库:192.168.137.197 需要先阅读并操作:ht ...
- C# 条形码 生成函数 (Code 128 标准
C# 条形码 生成函数 (Code 128 标准参考:GB/T 18347-2001) 最近在做单据打印,发现客户要求用到条形码,在网上找了,发现只有一些条形码的标准,但打出来发现根本不能扫,还要加某 ...
- cocos2d-x 动画加速与减速
转自:http://novacreo.com/%E7%A8%8B%E5%BA%8F%E7%BB%84/cocos2d-x%E5%8A%A8%E7%94%BB%E5%8A%A0%E9%80%9F%E4% ...
- 【转载】Android Studio 设置内存大小及原理
http://www.cnblogs.com/justinzhang/p/4274985.html http://tsroad.lofter.com/post/376316_69363ae Andro ...
- js过滤前后空格
页面中添加代码 String.prototype.trim=function() { return this.replace(/(^\s*)|(\s*$)/g,'');} 调用:title.tr ...
- C++在使用Qt中SLOT宏须要注意的一个小细节
大家都知道C++虚函数的机制,对于基类定义为虚函数的地方,子类假设覆写,在基类指针或者引用来指向子类的时候会实现动态绑定. 但假设指针去调用非虚函数,这个时候会调用C++的静态绑定,去推断当前的指针是 ...
- [Practical Git] Switching between current branch and last checkout branch
When working on a project, it is much easier to work on features and bugs in isolation of the rest o ...
- 信号之alarm和pause函数
使用alarm函数可以设置一个计时器,在将来某个指定的时间,该计时器会超时.当计时器超时时,产生SIGALRM信号.如果不忽略或不捕捉此信号,则其默认动作是终止调用该alarm函数的进程. #incl ...