jsp杂碎

 

解决中文无法显示的问题

1:修改区域设置:在控制面版中选择区域设置,设为英语(美国)?nbsp;

然后重起。一切就都正常。

2:在jsp页中加入一条语句:

<%@ page contentType="text/html;charset=gb2312" %> ?

?sp显示就正常了。

3:在编译servletjsp时加入代码选项。编译servlet使用

javac -encoding iso8859_1 myservlet.java

jspzone配置文件中.修改编译参数为:

compiler=builtin-javac -encoding ISO8859_1

使用这种方法后,不需要作其他的改动就可以正常显示中文了。

4:最土的办法,在servlet源程序中加入代码变换语句。如

try{

out.println(new ( (new String("hello world")).getBytes("GBK"),"ISO8859_1"))

}

catch( UnsupportedEncodingException e)

{

.......

}

使用这种方法一定要注意捕获UnsupportedEncodingException

 

页面传地递参数

post/getreguest.getParameter(“name”);

request的方法

字符串函数string

查找:Indexof() lastindexof()

截取:substring

 

跳转页面

window.location.href="logout.jsp"

 

application.setAttribute(“name”,”lion”); //设置参数

Enumeration data = application.getArributeNames();//取得所有变量的名称

Data.hasMoreElements()//判断是否还有变量

Data.nextElement()//取得下一个变量

Application.getAttribute(“name”)//取得变量的值

 

Config/Out/Page对象

 

DriverManager

Class.forName(“org.gjt.mm.mysql.Driver”);  //载入MYSQL驱动程式

getConnection(String url, String user, String password)  //与数据库建立连接

getDriver(String url) //打开指定地址的数据库驱动程式

 

Cookie

Cookie  classname = new Cookie(String index,String value);//建立Cookie

Response.addCookie(classname); //存储Cookie

Cookie[] AllCookies = request.getCookies(); //取得所有的Cookie

AllCookies[i].getName(); //取得index

AllCookies[i].getValue();//取得value

class.setMaxAge(Time); //设置Cookie的使用期限

 

Session

HttpSession mysession = request.getSession();

mysession.setAttribute("user",username);

String username = (String)mysession.getAttribute("user");

mysession.invalidate();

 

转化成汉字

String ToGB2312(String str)

{

  Byte GB2312[] = new byte[str.length()];

  for(int i=0; i<str.length(); i++)

  {

     GB2312[i] = (byte)str.charAt(i);

}

return new String(GB2312);

}

Jsp 指令
<%@taglib uri=”taglibraryURI” prefix=”tagPrefix”%>
//
让用户使用第三方标签
<jsp:forward page=”ForwardTo.jsp”>
<jsp:param name=”username” value=”Scott”/>
</jsp:forward>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值