情報システム科
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class a3Login3 extends HttpServlet {
//JSDK21.1レベルでのJSPの呼び出し@AB
//ServletContextのインスタンスをプロパティとして持たす
ServletContext ctx = null;
//@初期化ルーチンでServletContextの取得
public void init(ServletConfig config) {
synchronized(this) {
if(ctx == null) {
ctx = config.getServletContext();
}
}
}
public void service(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException {
//Webブラウザからの情報の読み取り
String userid = req.getParameter("userid");
String password = req.getParameter("password");
//セッションオブジェクトに保管
HttpSession session = req.getSession(true);
a3Useinfo3Bean bean = new a3Useinfo3Bean(userid,password);
session.setAttribute("userinfo",bean);
//画面を表示
//ARequestDispatcherの取得
res.setContentType("text/html; charset=Shift_JIS");
RequestDispatcher rd =
ctx.getRequestDispatcher("http://localhost:8080/xxx/a3login3.jsp");
//Bforward()メソッドの呼び出し
rd.forward(req,res);
}
}