[an error occurred while processing this directive]
[an error occurred while processing this directive]<%@ page pageEncoding="euc-jp" contentType="text/html; charset=UTF-8"%>
if((keyword = request.getParameter("keyword")) != null) {
keyword = new String(keyword.getBytes("iso-8859-1"), "utf-8");
}
import javax.servlet.*;
import javax.servlet.http.*;
public class MyServlet extends HttpServlet {
ServletContext context;
public void init(ServletConfig config) throws ServletException {
super.init(config);
context = config.getServletContext();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html; charset=euc-jp");
PrintWriter out = response.getWriter();
out.println("Hello!");
}
}
ブラウザでの表示結果
Hello!
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{
/* ここにpostの処理 */
/* 例えばindex.jspに処理を飛ばしてみる */
String name = "kei";
request.setAttribute("name_a", name);
context.getRequestDispatcher("/index.jsp").forward(request, response);
}
飛ばす先のjspファイル。(index.jsp)
<%@ page contentType="text/html; charset=euc-jp" %>
<% String name = (String)request.getAttribute("name_a"); %>
<html><body>
Hi, I'm <%= name %> !
</body></html>
ブラウザでの表示結果
Hi, I'm kei!
response.sendRedirect("http://www.sodan.ecc.u-tokyo.ac.jp/~kei/perl/simple.cgi");