powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / кодировка в URL
3 сообщений из 3, страница 1 из 1
кодировка в URL
    #37979459
planetka
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Сервлет выводит файлы из директории. Проблема возникает с html-файлами с русскими буквами, гиперсылка не открывается. Кодировка utf-8.

Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
package com.prognoz;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/FilesReestrServlet")
public class FileRegisterServlet extends HttpServlet{
	private String						param;
	private static final long	serialVersionUID	= 1L;

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{

		param = getServletContext().getInitParameter("dirToShow");

		response.setContentType("text/html");
		response.setCharacterEncoding("utf-8");
		ServletOutputStream out = response.getOutputStream();

		File reestr = new File(getServletContext().getRealPath(param));

		param = getServletContext().getContextPath()+"/"+param;

		File[] fileList = reestr.listFiles();

		out.println("<H2><FONT COLOR=TEAL>"+
								"Total number of files in the choosen directory - "+
								fileList.length+"</FONT></H2>");

		out.println("<H3><FONT COLOR=PURPLE>"+
								"Directory path - "+
								param+
								"</FONT></H3><HR>");

		out.println("<TABLE BORDER=0 CELLSPACING=5>");

		for(File element: fileList)
			printName(element, out);

		out.println("</TABLE><HR>");

	}

	private void printName(File name, ServletOutputStream out)
	{
		try
		{
			
			out.write(("<tr><td><a href=\""+param+"\\"+name.getName()+"\">"+name.getName()+"</a></td></tr>").getBytes("utf-8"));
					
		}
		catch(UnsupportedEncodingException e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch(IOException e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public String getServletInfo()
	{
		return "This servlet shows a content of a directory"+
						"mentioned in dirToShow parameter or property.";
	}
}




Не знаю что еще можно изменить
...
Рейтинг: 0 / 0
кодировка в URL
    #37979499
пролетевший
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
...
Рейтинг: 0 / 0
кодировка в URL
    #37981422
planetka
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
пролетевший,

Спасибо =)
...
Рейтинг: 0 / 0
3 сообщений из 3, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / кодировка в URL
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]