首页 文章 精选 留言 我的

精选列表

搜索[网站开发],共10000篇文章
优秀的个人博客,低调大师

JSP web应用程序开发教程实验一

版权声明:转载请注明出处:http://blog.csdn.net/dajitui2024 https://blog.csdn.net/dajitui2024/article/details/79396232 编码统一utf-8 文件名:a.jsp <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <html> <head> </head> <body> <% int num = Integer.parseInt(request.getParameter("num")); out.println(num+"的平方是:"+num*num); %> </body> </html> 文件名:b.jsp <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <html> <head> </head> <body> <jsp:include page="a.jsp"> <jsp:param value="19" name="num"/> </jsp:include> </body> </html> 文件名:ex201.jsp <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <html> <head> </head> <body> <% Date date = new Date(); int hour = date.getHours(); int minute = date.getMinutes(); int second = date.getSeconds(); if (hour >= 0 && hour < 12) { out.println("早上好!"); } else if (hour >= 12 && hour < 19) { out.println("下午好!"); } else { out.println("晚上好!"); } %> </body> </html> 文件名:test1.jsp <%@ page contentType="text/html;charset=utf-8" %> <% request.setCharacterEncoding("utf-8"); String strUserName = ""; strUserName = (String)request.getParameter("UserID"); if(strUserName.equals("张三")){ out.println("你好" + strUserName); }else{ out.println("名称错误"); } %> <br>姓名:<%=strUserName%><br> 文件名:test2.jsp <%@ page contentType="text/html;charset=utf-8" %> <html><body> <form action= " test1.jsp" method="post"> <p>姓名:<input type="text" size="20" name= "UserID"></p> <p><input type="submit" value="提 交"> </p> </form> </body></html>

优秀的个人博客,低调大师

Android开发学习笔记:数据存取之File浅析

Android系统中提供了一种文件读写的方法,可以将一些数据以文件的形式保存在设备中。比如一些word文档,PDF文档,图片,音频,视频文件等。 使用文件读写方法的步骤: 1.调用Context.openFileInput()方法获得Java文件输入流(FileInputStream) 2.调用Context.openFileOutput()方法获得java文件输出流(FileOutputStream) 3.使用Resources.openRawResource(R.raw.DataFile)方法返回InputStream 下面的具体实例,在一个Activity里面创建两个EditText和两个Button,第一个EditText和Button将EditText的内容写到文件file.txt文件中。第二个EditText和Button将内容从文件file.txt中读取出来显示。文件被默认保存在/data/data/package/files下面。 MainActivity.java packagecom.android.file; importjava.io.FileInputStream; importjava.io.FileOutputStream; importandroid.app.Activity; importandroid.os.Bundle; importandroid.view.View; importandroid.view.View.OnClickListener; importandroid.widget.Button; importandroid.widget.EditText; publicclassMainActivityextendsActivity{ //声明文件名字符串常量 privatestaticfinalStringFILE_NAME="file.txt"; privateButtonwriteBtn,readBtn; privateEditTextwriteText,readText; @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); writeBtn=(Button)findViewById(R.id.Button1); readBtn=(Button)findViewById(R.id.Button2); writeText=(EditText)findViewById(R.id.EditText1); readText=(EditText)findViewById(R.id.EditText2); writeBtn.setOnClickListener(newOnClickListener(){ @Override publicvoidonClick(Viewv){ //写内容 write(writeText.getText().toString()); } }); readBtn.setOnClickListener(newOnClickListener(){ @Override publicvoidonClick(Viewv){ //读内容 readText.setText(read()); } }); } privateStringread(){ try{ //实例化文件输入流对象 FileInputStreamfis=openFileInput(FILE_NAME); //定义缓存数组 byte[]buffer=newbyte[fis.available()]; //读到缓冲区 fis.read(buffer); returnnewString(buffer); }catch(Exceptione){ e.printStackTrace(); } returnnull; } privatevoidwrite(Stringcontent){ try{ //实例化文件输出流 //openFileOutput(Stringname,intmode) //第一个参数文件名 //第二个是模式 //MODE_APPEND表示要创建的文件存在则新写入的数据不会覆盖以前的数据。 FileOutputStreamfos=openFileOutput(FILE_NAME,MODE_APPEND); //写内容 fos.write(content.getBytes()); //关闭文件流 fos.close(); }catch(Exceptione){ e.printStackTrace(); } } } main.java <?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="请被文本输入内容" /> <EditText android:text="" android:id="@+id/EditText1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:height="100px" /> <Button android:id="@+id/Button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="写数据" /> <EditText android:text="" android:id="@+id/EditText2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:height="100px" /> <Button android:id="@+id/Button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="读数据" /> </LinearLayout> 效果图: 在终端下输入“adb shell”命令进入Android系统查看一下我们的文件是否写入成功。 本文转自 lingdududu 51CTO博客,原文链接:http://blog.51cto.com/liangruijun/660540

优秀的个人博客,低调大师

开发者笔记】MQTT python测试笔记

MQTT是基于订阅/发布的物联网协议。 python测试需要一个发送进程和接收进程,即一个发送客户端和一个接收客户端,如果这两个客户端工作在同一个topic下,那么就能进行消息互通了。 服务器用“iot.eclipse.org”就好了,避免了自己搭建服务器,然后流程还可以跑通。 发送客户端代码: import paho.mqtt.client as mqtt import paho.mqtt.publish as publish idx = 0#往paho/temperature 一直发送内容 while True: print("send success") publish.single("paho/temperature", payload="this is message:%s"%idx, hostname="iot.eclipse.org", client_id="lora1", # qos = 0, # tls=tls, port=1883, protocol=mqtt.MQTTv311) idx += 1 接收客户端代码: import paho.mqtt.client as mqtt # The callback for when the client receives a CONNACK response from the server. def on_connect(client, userdata, flags, rc): print("Connected with result code "+str(rc)) # The callback for when a PUBLISH message is received from the server. def on_message(client, userdata, msg): #在这里处理业务逻辑 print(msg.topic+" "+str(msg.payload)) client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message client.connect("iot.eclipse.org", 1883, 60)#订阅频道 client.subscribe("paho/temperature") # Blocking call that processes network traffic, dispatches callbacks and # handles reconnecting. # Other loop*() functions are available that give a threaded interface and a # manual interface. client.loop_forever() 然后运行两个客户端,就可以在接收端收到消息了。 MQTT服务器不负责存储数据,需要编写额外的接收客户端来接收数据、分析、入库等。 MQTT服务器用的是iot.eclipse.org,如果碰巧两个人在用同一个频道,那可能收到别人的消息哦~ 如果要搭建自己的MQTT服务器,那么回头再说。 玩一玩就好了,不要给服务器增加太多负担哟~ 参考资料: paho-qtt说明文档 黑夜给了我黑色的眼睛,我却用它寻找光明

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册