日期:2014-05-17  浏览次数:20689 次

<html:link>的讲解和编码的讲解

<%@ page  language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="com.form.TestForm"%>
<%@page import="com.form.Person"%>
<%@page import="com.form.Go"%>
<%@page import="java.net.URLEncoder"%>
<%@ taglib prefix="html" uri="http://jakarta.apache.org/struts/tags-html"%>

<%
 request.setAttribute("name", "曹欢操");
 Date date = new Date();
 request.setAttribute("date", date);
 Person person1 = new Person();
 person1.setId(1);
 person1.setName("a");
 
 Person person2 = new Person();
 person2.setId(1);
 person2.setName("a");
 
 Person person3 = new Person();
 person3.setId(1);
 person3.setName("a");
 Go go = new Go();
 Map map = go.getMap();
 
 map.put("x",person1);
 map.put("y",person2);
 map.put("z",person3);
 
 request.setAttribute("go", go);
 
%>

 

<!-- 这是将保存在request中的name的值赋值给paramId中的userName -->
<html:link  action="/testGoGo1.htm?p=go" paramId="userName" paramName="name">点击</html:link>很好 可以自动拦截以任何东西结尾的
<!-- 这是将保存在request中的name对象的time属性赋值给paramId中的now -->
<html:link  action="/testGoGo1.htm?p=go" paramId="now" paramName="date" paramProperty="time">点击</html:link>
<!--这是将go对象的map属性(脸面包含喝多对象)  -->
<html:link  action="/testGoGo1.htm?p=go"    name="go" property="map">点击</html:link>

<a href="${pageContext.request.contextPath}/testGoGo1.htm?p=go&userName=${name}">电机及</a>

 

<%
 //如果不进行编码的的在后台得到的id的值就是asd,但是如果通过编码的话就是asd&go
  String s = URLEncoder.encode("asd&go","utf-8");
  request.setAttribute("s",s);
%>
 <a href="${pageContext.request.contextPath}/testGoGo1.htm?p=go&id=${s}">点击</a>;
 

//name相当于select的name属性

<html:select property="name">

//list是保存在request的一个属性(里面保存的一个一个的对象),id是list中的对象的id属性,name同id一样
      <html:optionsCollection name="list" value="id" label="name"/>

 

1、URLEncoder是对字符编码,   

  URLDecoder是对字符进行解码:   
  1.大写字母A-Z   
  2.小写字母a-z   
  3.数字   0-9   
  4.标点符   "."     "-"     "*"     and   "_"   
    不会被编码,是安全的,   
  我就搞不懂,它们所指别的字符的都是不安全的,究竟是哪不安全,能不能举个例子??   
  另外,这种编码解码在WEB开发中,有什么意义,能不能举个例子?   

 

2、举个简单例子:   
  text   =   "abcd";url   =   "a.jsp?text="+text;   
  这样没有问题   
  但是当text   =   "abcd&edf";     这样url就是"a.jsp?text=abcd&edf"   
  request.getParameter就获得abcd,剩余的就解析为另外一个参数edf   
  所以需要对符号"&"编码

 

3、举个简单例子:

  String   value1="123&中文";   
  String   enc="UTF-8";   
  String   url="Http://localhost:8080/forum.jsp?id="+URLEncoder.encoder(value1,enc);