如何用Java代码实现
在servlet里面写就可以了
成都创新互联是专业的银海网站建设公司,银海接单;提供网站设计、成都做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行银海网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
引入一系列包
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
public class Servlet1 extends HttpServlet {
public void doGet(ServletRequest req,ServletResponse res)throws ServletException, IOException{try{PrintWriter pw=res.getWriter();//在浏览器输出需要
pw.println("scriptscript");}catch(Exception e){
e.printStackTrace();//为发现调试错误}}}
试试吧,就是这样就可以了,把你要输出的HTML这些放在 pw.println("这里放HTML");就OK了
用java代码实现
package test;
import java.awt.FlowLayout;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class FrameDemo extends JFrame implements Runnable {
public void run() {
try{
while(true){
Date date=new Date();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月");
SimpleDateFormat sdf1=new SimpleDateFormat("dd");
SimpleDateFormat sdf2=new SimpleDateFormat("hh:mm:ss");
String week=getWeekOfDate(date);
GregorianCalendar ca = new GregorianCalendar();
String apm="";
int check=ca.get(GregorianCalendar.AM_PM);
if(check==0){
apm="上午";
}else if(check==1){
apm="下午";
}
JLabel jl = new JLabel("html"
+ "div align='center'"+sdf.format(date)+"/div"
+ "div align='center'font size=50"+sdf1.format(date)+"/font日/div"
+ "div align='center'"+week+"/div"
+ "div align='center'"+apm+sdf2.format(date)+"/div"
+ "/html");
add(jl);
setLayout(new FlowLayout());
setSize(150,150);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
Thread.sleep(1000);
//jl.setText(null);
remove(jl);
}
}catch(Exception e){}
}
public static String getWeekOfDate(Date dt) {
String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
Calendar cal = Calendar.getInstance();
cal.setTime(dt);
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w 0)
w = 0;
return weekDays[w];
}
public static void main(String[] args) {
FrameDemo mr = new FrameDemo();
Thread t1 = new Thread(mr);
t1.start();
}
}
怎么写java代码?
只要自己的电脑安装了jdk环境,任何地方都可以进行java代码的编写的,记事本也可以。
分享名称:如何使用java代码实现,java怎么实现
标题URL:http://lswzjz.com/article/dscjgep.html