الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

حل مشكلة العربيه في خطوتين فقط لبرامج ال Jsp و ال Struts

بدأه mhewedy في 10 يناير 2009 · 4 رد · 2,350 مشاهدة · في JavaEE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

بســم الله الـرحمــن الرحيــم

بحمد لله ثم بفضل الأعضاء هنا توصلت لحل مشكلة اللغه العربيه في برامج ال JSP و ال Struts

و قمت بتنظيم طريقة الحل و وضعتها هنا

http://m-hewedy.blogspot.com/2009/01/enabl...n-java-web.html

شكرا لكم

#2

المدونة لا تفتح عندي ..او قد تكون محظورة من نوع الاتصال الذي استخدمه

هل لك ان تدرج الموضوع كاملا هنا

بالتوفيق

الله معك..

#3

الموضوع باللغه الإنجليزيه للاسف و لم اقم بترجمته للعربيه بعد , و على ذلك ساقوم بنشره هنا مع الإعتزار للأخوه المشرفين

Enabling Arabic in Java web applications (JSP apps and Struts apps )

One of the most big problems you can face as a java web developer is how

to make you web application accepts Arabic (non-ISO-8859-1 characters)

characters from the users in the input text boxes.

In JSP/Servlet applications, a small googling can solve the problem, but

with a framework such as Struts, the matter differ somewhat.

If your web application uses the Database ( the most if not all does )

you should insure that the problem is not in the Database itself that cannot

save Arabic characters, you should try hand-entering Arabic words in varchar

and nvarchar fields, if it accepts Arabic characters, then the problem is in

the JSP/Servlet or Struts and you will find the solution here.

For pure JSP/Servlet Applications :

Two steps and every thing well be done.

First: in each JSP page write this tag at the top of the page :

<%@page language="java" contentType="text/html; charset=UTF-8"%>

Second : in each Servlet that works as the controller for you JSPs, write these two statements at the top of your service()/doGet()/doPost() methods.


response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");

That’s all about Enabling Arabic character acceptation in your JSP forms

For Struts Applications:

Also two steps :

First: in each JSP page write this tag at the top of the page :

<%@page language="java" contentType="text/html; charset=UTF-8"%>

Second: write a Filter class the wraps your org.apache.struts.action.ActionServlet class and put these two statements in its doFilter() method



response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");

example filter :



private void doBeforeProcessing(ServletRequest request, ServletResponse response)

throws IOException, ServletException {

request.setCharacterEncoding("UTF-8");

response.setCharacterEncoding("UTF-8");

}

private void doAfterProcessing(ServletRequest
request, ServletResponse response) throws IOException, ServletException {

}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)throws IOException, ServletException {

doBeforeProcessing(request, response);

Throwable problem = null;

try {

chain.doFilter(request, response);

} catch(Throwable t) {

problem = t;

t.printStackTrace();

}

doAfterProcessing(request, response);

}}}
public class ArabicEncodingFilter implements Filter {

And then wrap all your Servlets with you Filter by putting this in web.xml :




<filter-name>EncodingFilter</filter-name>

<filter-class>ArabicEncodingFilter</filter-class>

</filter>

<filter-mapping>

<filter-name>EncodingFilter</filter-name>


<url-pattern>/*</url-pattern>


</filter-mapping>
<filter>

#4

جزاك الله خيرا هويدي ،

وجزى الله خيرا الأخ علاء الصالحي الذي دلني على هذا الموضوع .

300_130.gif

#5

غفر الله لنا جميعا

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…