黄森huang
2016-11-07 16:18
但是效果确是这样的,求解问题在哪?
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%> <%@page import="java.text.*" %> <%@page import="java.lang.String" %> <% 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 'index.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> <!-- 我是html注释,可在客户端看见 --> <%--我是JSp注释,在客户端不可见 --%> <% /*我是脚步注释*/ %> <h1>九九乘法表</h1> <hr> <%!//定义自定义变量或方法 String fangfa(){ String s=""; for(int i=1;i<=9;i++){ for(int j=1;j<=i;j++){ int c=i*j; s=i+"*"+j+"="+c; } s=s+"<br>"; } return s; } %> <% SimpleDateFormat date=new SimpleDateFormat("yyyy/MM/dd"); String d =date.format(new Date()); %> 今天是:<%=d %>+"<br>" <%=fangfa()%> </body> </html>
改成s+=i+"*"+j+"="+c; 试试
for(int i=1;i<=9;i++){ for(int j=1;j<=i;j++){ int c=i*j; s=i+"*"+j+"="+c; } s=s+"<br>"; } return s; }
s=i+"*"+j+"="+c return的s在这里被覆盖了
JAVA遇见HTML——JSP篇
248277 学习 · 3071 问题
相似问题