首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

struts2和json集成编码有关问题

2012-09-01 
struts2和json集成编码问题小菜学struts2,据说编码格式必须为 constantname struts.i18n.encoding val

struts2和json集成编码问题
小菜学struts2   ,据说编码格式必须为 <constant   name= "struts.i18n.encoding "   value= "UTF-8 "> </constant>
但是我写的程序,如果是gbk,可以运行json   ,但是如果是utf-8   ,则没反应,奇怪了
配置文件
<constant   name= "struts.custom.i18n.resources "   value= "messageResource "> </constant>
<!--   定义web应用的默认编码集   -->
<constant   name= "struts.i18n.encoding "   value= "UTF-8 "> </constant>
<!--   定义可以动态method模式进行Action访问   -->
<constant   name= "struts.enable.DynamicMethodInvocation "   value= "true "> </constant>
<constant   name= "struts.ui.theme "   value= "simple "   />  
<constant   name= "struts.ui.templateDir "   value= "template "   />  
<constant   name= "struts.ui.templateSuffix "   value= "ftl "   />  
<constant   name= "struts.locale "   value= "zh_CN "> </constant>

<!--   使用ajaxaction处理类的跳转结果   -->
<action   name= "validName "   class= "com.hbxyf.action.UserAjaxAction ">
<result   type= "json "   />
<interceptor-ref   name= "defaultStack "   />
</action>


<%@   page   language= "java "   import= "java.util.* "   pageEncoding= "utf-8 "%>
<%@taglib   prefix= "s "   uri= "/struts-tags "%>
<%
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> 用户添加 </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= "navigation/stylee.css ">
<script   src= "sxhtml/prototype-1.4.0.js "   type= "text/javascript "> </script>
<script   src= "sxhtml/json.js "   type= "text/javascript "> </script>
<script   language= "JavaScript ">
function   validateName()
{
document.getElementById( "tip ").innerHTML   = " ";
if(document.getElementById( "login ").value== " "){
return   ;
}
//请求的地址
var   url   =   'validName.action ';
//使用Prototype.js函数库来创建请求参数
var   params   =   Form.Element.serialize( 'login ');


//创建Ajax.Request对象,对应于发送请求
var   myAjax   =   new   Ajax.Request(
url,
{
//请求方式:POST
method: 'post ',
//请求参数
parameters:params,
//指定回调函数
onComplete:   processResponse,
//是否异步发送请求
asynchronous:true
});
}
function   processResponse(request)
{
//使用pareseJSON()方法把服务器响应解析成一个json对象
var   action   =   request.responseText.parseJSON();
//将json对象的tip属性在tip元素中输出
$( "tip ").innerHTML   =   action.tip;
}
</script>
<STYLE   type= "text/css ">
.t{
font-family:宋体;
FONT-SIZE:   12px;
}
</STYLE>
    </head>
   
    <body>
    <jsp:include   page= "title.jsp "> </jsp:include>
    <div   align= "center "   style= "margin-top:   40px; ">
            <b>  
            用户信息设置
            </b>
            </div>
        <s:form   action= "adduser.action "   method= "post "   theme= "simple ">
          <table   align= "center "   width= "40% "   border= "1 "   bordercolordark= "#ffffff "   bordercolorlight= "#BDBCC9 "   cellpadding= "0 "   cellspacing= "0 "   >
            <tr   onMouseOver= "this.bgColor= '#cccccc ' "   onMouseOut= "this.bgColor= '#ffffff ' ">
            <td   align= "center "> 姓名: </td>
            <td>
<s:textfield     name= "user "   size= "15 "   cssClass= "t "/>
<font   style= "color:   red "> * </font>
<s:fielderror   cssStyle= "color:red; ">
<s:param> user </s:param>
</s:fielderror>
</td>
                </tr>
                <tr   onMouseOver= "this.bgColor= '#cccccc ' "   onMouseOut= "this.bgColor= '#ffffff ' ">
            <td   align= "center "   width= "30% ">
用户名:
</td>
            <td   align= "left ">
<s:textfield     name= "login "   size= "15 "   id= "login "   onblur= "validateName() "/>
<font   style= "color:   red "> * </font>
<span   id= "tip "   style= "color:red;font-weight:bold "> </span>
<s:fielderror   cssStyle= "color:red; ">
<s:param> login </s:param>
</s:fielderror>
</td>
                </tr>


很是奇怪啊,就根本进不到后台,奇怪了

------解决方案--------------------


utf-8不行啊?
那你在web.xml配置下看看

Java code
<filter>        <filter-name>struts2</filter-name>        <filter-class>            org.apache.struts2.dispatcher.FilterDispatcher        </filter-class>    </filter>    <filter-mapping>        <filter-name>struts2</filter-name>        <url-pattern>/*</url-pattern>    </filter-mapping>
[解决办法]
调试,看看js的执行
[解决办法]
HTML code
不懂帮顶学习蹭分
[解决办法]
探讨
难道是我缺少相应的jar包?

热点排行