各位大虾,我在用struts做一个JSP的课程设计,在做的过程中涉及到对数据的修改,在数据修改的页面上要通过request.getAttribute(如下代码)从action文件接收要修改的数据显示在文本框中,在修改完后通过hibernate更新到数据库。在JSP页面中我以在页顶设置了UTF-8,jsp页面接收到数据也是正常的,但是到参数从文本框用表单重新才传回到action表单进而更新到数据库时发现数据变成了乱码,我在action.java中输出了接收到的参数,发现确实是乱码,就是说错误发生在JSP页面传回修改数据时。不知道这是怎么,希望有知道的大虾能够帮我一下,感激不尽。
<html:form action="/gDJC002?action=" enctype="multipart/form-data">
<html:text property="txtTitle" value="<%=(String)request.getAttribute("FDvdTitle")%>"/></div> <html:text property="txtYearM" value="<%=request.getAttribute("FYear").toString()%>"/> 年</div>
<html:text property="txtType" value="<%=(String)request.getAttribute("FType")%>"/></div>
<html:text property="txtNation" value="<%=(String)request.getAttribute("FCountry")%>"/></div>
<html:text property="txtPrice" value="<%=(String)request.getAttribute("FPrice").toString()%>"/> 元 <html:submit value=" 确定 "/>
<html:reset value=" 重置 " />
</html:form>
<html:form action="/gDJC002?action=" enctype="multipart/form-data">
<html:text property="txtTitle" value="<%=(String)request.getAttribute("FDvdTitle")%>"/></div> <html:text property="txtYearM" value="<%=request.getAttribute("FYear").toString()%>"/> 年</div>
<html:text property="txtType" value="<%=(String)request.getAttribute("FType")%>"/></div>
<html:text property="txtNation" value="<%=(String)request.getAttribute("FCountry")%>"/></div>
<html:text property="txtPrice" value="<%=(String)request.getAttribute("FPrice").toString()%>"/> 元 <html:submit value=" 确定 "/>
<html:reset value=" 重置 " />
</html:form>
tomcat中默认字符编码也可以改为utf-8 在server.xml中 修改