Struts2¿ò¼ÜJSPÒ³Ãæ´«ÊäÖÐÎÄÂÒÂëÎÊÌâ½â¾ö
Action´úÂë
package com.zxc.action;import java.net.URLEncoder;public class XiaoZAction {
private String username; public String getUsername() { return username; }
public String execute() throws Exception{
username = URLEncoder.encode("ÖÜС´¨", "utf-8"); return "success"; }}
struts.xml´úÂë
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="xzc" namespace="/test" extends="struts-default">
<action name="list" class="cn.itcast.action.XiaoZAction">
<result type="redirect">/xiaox.jsp?username=${username}</result>
</action>
</package>
</struts>
jspÒ³Ãæ´úÂë
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="java.net.URLDecoder"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'xiaox.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" mce_href="styles.css">
-->
</head>
<body>
<%
byte[] b = request.getParameter("username").getBytes("ISO8859-1");
String a = new String(b,"utf-8");
%>
<%=URLDecoder.decode(a,"utf-8") %>
<form action="/xiaox">
username:<input type="text" name="xiaox">
</form>
</body>
</html>
Ïà¹ØÎĵµ£º
ÔÎĵØÖ·£ºhttp://hi.baidu.com/wangking/blog/item/8a109423ff3d2341ac34dec9.html
ÔÚJava web¿ª·¢Öг£»áʹÓõ½¹¦ÄÜÇ¿´óµÄ¹ýÂËÆ÷£¬Ëû±Ï¾¹ÄܸøÎÒÃÇ´øÀ´ºÜ´óµÄ·½±ã£¬µ«ÊÇÕë¶Ô¹ýÂ˵Ä×ÊÔ´ÎÒÃÇÐèÒªÏêϸµÄÁ˽âËûÃÇÔÚweb.xmlÖеÄÅäÖÃÐÅÏ¢¡£Õâ¸ö¸ù¾Ý¼¸ÖÖ³£ÓõIJ»Í¬Çé¿ö½øÐÐÁË×ܽ᣺
1¡£Èç¹ûÒªÓ³Éä¹ýÂËÓ¦ÓóÌÐòÖÐËùÓÐ×ÊÔ´£º
< ......
ÔÚ±¾ÆªÎÄÕÂÖн«Ê¹ÓùýÂËÆ÷½øÐбàÂëת»»¡¢µÇ½ÑéÖ¤¡¢·ÀÕ¾ÍâÌá½»µÄ¹ý³Ì£¬ÎªÁËÑÝʾ£¬ÎҰѱàÂëת»»·ÅÔÚÒ»¸öfilterÖУ¬µÇ½ÑéÖ¤ºÍ·ÀÕ¾ÍâÌá½»·ÅÔÚÁíÒ»¸öfilterÖУ¬Á½¸öfilter½øÐд®Áª¹¤×÷¡£
1¡¢ÎªÁËÑÝʾ£¬ÏÈÖÆ×÷ÕâÁ½¸öfilter
//Õâ¸öfilterÊÇΪÁË×ö±àÂëת»»£¬Ö»Òª·ÃÎÊ.jspÍøÒ³¶¼Òª¹¦¹ýÕâ¸öfilter
/**ÀàÃû£ºfilter.Encoding
*×÷ ......
JSPµÄ×¢ÊÍ
<%--........--%>
JSPÖ¸ÁîºÍJSP¶¯×÷£¨±ê×¼µÄJSP±êÇ©£©
JSPÖ¸ÁîµÄÓï·¨
<%@... ....%>
<%@include file="...."%> °üº¬Ö¸Á°üº¬Ö¸Áî»á½«Òª°üº¬µÄÎļþ´úÂëÔÑùÊä³öµ½±¾Ò³Ã棨ÔÚ·Òëʱ°Ñ°üº¬ÎļþµÄÄÚÈÝÒýÈë²¢ºÏ²¢£©£¬²»½øÐзÒ룬fileÊôÐÔÖƶ¨Òª°üº¬µÄÎļþµÄÃû×Ö£¨×¢ÒâÒª°üº¬µÄÎļþµÄ·¾¶£©£ ......
Ò»¡¢ÏÈ¿´¿´ÈçºÎÈ¡µ±Ç°Ê±¼ä²¢ÏÔʾµÄ´úÂ룺
------------------------------------------------
<%
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
java.util.Date currentTime = new java.util.Date();//µÃµ½µ±Ç°ÏµÍ³Ê±¼ä
String str_date1 = formatter.form ......