一个简单的JSP程序怎么无法显示呢???
如题,代码如下:
- JScript code
<%@ page contentType="text/html;charset=gb2312" language="java" errorPage="" %><%@ page import="java.util.Date,java.text.SimpleDateFormat" %><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'example1.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <% Date date=new Date(); String dateFormatStr="BJ time:\n\tH:mm:ss\n\tE\n\tyyyy-M-dd"; SimpleDateFormat simpleFormat=new SimpleDateFormat(dateFormatStr); out.println("<h3>now time:"+simpleFormat.format(date)+"</h3><br>"); int hours=date.getHours(); String msg=""; if(hours==1) msg="please have a rest!!!"; if(hours==0) msg="what's wrong with you???"; out.println("<h3><font color=red>"+msg+"</font></h3>"); %> </body> </html> [解决办法]
- Java code
String dateFormatStr="BJ time:\n\tH:mm:ss\n\tE\n\tyyyy-M-dd"; SimpleDateFormat simpleFormat=new SimpleDateFormat(dateFormatStr);
[解决办法]
out.println("<h3><font color=red>"+msg+"</font></h3>");
lz是要显示在哪?
[解决办法]
1.String dateFormatStr="BJ time:\n\tH:mm:ss\n\tE\n\tyyyy-M-dd";
中格式不合法,把BJ time去掉改为String dateFormatStr="\n\tH:mm:ss\n\tE\n\tyyyy-M-dd";
2.用example1.jsp作为ajax的输出结果页面之需要下面这样就行
- HTML code
<%@ page contentType="text/html;charset=gb2312" language="java" errorPage="" %><%@ page import="java.util.Date,java.text.SimpleDateFormat" %> <% Date date=new Date(); String dateFormatStr="\n\tH:mm:ss\n\tE\n\tyyyy-M-dd"; SimpleDateFormat simpleFormat=new SimpleDateFormat(dateFormatStr); out.println("<h3>now time:"+simpleFormat.format(date)+"</h3><br>"); int hours=date.getHours(); String msg=""; if(hours==1) msg="please have a rest!!!"; if(hours==0) msg="what's wrong with you???"; out.println("<h3><font color=red>"+msg+"</font></h3>"); %>
[解决办法]
我测试了一下是有反应的,只是第一次点击能返回时间,再后面的点击就不行了,因为缓存的原因,加一个随机数就可以了
function startRequest()
{
createXMLHttpRequest();
xmlHttp.onreadystatechange=handleStateChange;
var random = Math.random();
xmlHttp.open("GET","example1.jsp?"+random,true);
xmlHttp.send(null);
}