1,jsp的9大内置对象
request,response,session,application,page,pageContext,out,config,exception
查过资料了,现在补充一下;
JSP中九大内置对象为:
request 请求对象 类型 javax.servlet.ServletRequest 作用域 Request
response 响应对象 类型 javax.servlet.SrvletResponse 作用域 Page
pageContext 页面上下文对象 类型 javax.servlet.jsp.PageContext 作用域 Page
session 会话对象 类型 javax.servlet.http.HttpSession 作用域 Session
application 应用程序对象 类型 javax.servlet.ServletContext 作用域 Application
out 输出对象 类型 javax.servlet.jsp.JspWriter 作用域 Page
config 配置对象 类型 javax.servlet.ServletConfig 作用域 Page
page 页面对象 类型 javax.lang.Object 作用域 Page
exception 例外对象 类型 javax.lang.Throwable 作用域 page
2,哪个标签点击文字会聚焦到text文本输入框,答案是<input type="text" id="text1"><label for="text1">text1</label>
3,输出乘法口诀
public static void pringChengfakoujue()
{
System.out.println("乘法口诀表");
for(int outNum=1;outNum<=9;outNum++)
{
for(int innerNum=1;innerNum<=9;innerNum++)
{
if(outNum>=innerNum)
{
System.out.print("[" + innerNum + "*" + outNum + "=" + (outNum * innerNum) + "]");
}
}
System.out.println();
}
}
4,用数组实现一个栈,接口如下:
public interface IStatck {
Object pop();
int size();
void push(Object obj);
}
实现代码:
package org.tws;
/**
* Created with IntelliJ IDEA.
* User: cutter.li
* Date: 14-3-4
* Time: 下午4:25
* To change this template use File | Settings | File Templates.
*/
public class ArrayStack implements IStatck {
private Object[] objArray;
public ArrayStack(Object[] objArray)
{
this.objArray=objArray;
}
@Override
public Object pop() {
if(null==objArray){
return null;
}
return objArray[objArray.length-1];
}
@Override
public int size() {
if(null==objArray) {
return 0;
}
return objArray.length;
}
@Override
public void push(Object obj) {
int length=size();
if(length==0)
{
objArray=new Object[]{obj};
} else
{
Object[] objArray2=new Object[length+1];
System.arraycopy(objArray,0,objArray2,0,length-1);
objArray2[length]=obj;
objArray=objArray2;
}
}
}
5,sql的行列转换
select departmentname as '部门'
, sum(if(monthName=1,icome,0)) as '一月份'
, sum(if(monthName=2,icome,0)) as '二月份'
, sum(if(monthName=3,icome,0)) as '三月份'
, sum(icome) as '总收入'
from t_icome group by departmentName ;
数据准备:
CREATE TABLE `t_icome` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`departmentName` varchar(3) NOT NULL,
`monthName` int(11) NOT NULL,
`icome` float NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
INSERT INTO `t_icome` VALUES ('1', 'a', '1', '2000');
INSERT INTO `t_icome` VALUES ('2', 'a', '2', '2500');
INSERT INTO `t_icome` VALUES ('3', 'b', '1', '2500');
INSERT INTO `t_icome` VALUES ('4', 'b', '2', '2600');
INSERT INTO `t_icome` VALUES ('5', 'a', '3', '2600');
INSERT INTO `t_icome` VALUES ('6', 'b', '3', '2900');
INSERT INTO `t_icome` VALUES ('7', 'c', '1', '2900');
INSERT INTO `t_icome` VALUES ('8', 'c', '2', '2900');
6,数据去重
两张结构相同的表,查找在表a中不在表b的数据;
数据和表:
DROP TABLE IF EXISTS `t_a`;
CREATE TABLE `t_a` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`no` varchar(20) DEFAULT NULL,
`product` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;
INSERT INTO `t_a` VALUES ('1', 'aaa', 'xxx');
INSERT INTO `t_a` VALUES ('2', 'bbb', 'xyz');
INSERT INTO `t_a` VALUES ('3', 'aaa', 'aaa');
INSERT INTO `t_a` VALUES ('4', 'aaa', 'ddd');
DROP TABLE IF EXISTS `t_b`;
CREATE TABLE `t_b` (
`id` int(11) NOT NULL DEFAULT '0',
`no` varchar(20) DEFAULT NULL,
`product` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `t_b` VALUES ('1', 'aaa', 'xyz');
INSERT INTO `t_b` VALUES ('2', 'aaa', 'aaa');
INSERT INTO `t_b` VALUES ('3', 'aaa', 'fuck');
INSERT INTO `t_b` VALUES ('4', 'bbb', 'ccc');
INSERT INTO `t_b` VALUES ('5', 'bbb', 'nimei');
sql写法:
SELECT a.* FROM
t_a a
LEFT JOIN
t_b b ON a.no = b.no and a.product=b.product
WHERE b.no IS NULL and b.product is null;