import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class shori extends HttpServlet {
public void service(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
//セッション開始
HttpSession session = request.getSession(true);
//==============================//
// データの取得 //
//==============================//
//Fromの引数取得
String nyuryoku = request.getParameter("nyuryoku");
if ( nyuryoku == null )
{
session.setAttribute("msg","なにも入力されてません");
getServletContext().getRequestDispatcher("/jsp/index.jsp").forward(request,response);
}
else if ( nyuryoku.length() == 0 )
{
session.setAttribute("msg","なにも入力されてません");
getServletContext().getRequestDispatcher("/jsp/index.jsp").forward(request,response);
}
// 処理
int i,atari;
atari = 0;
String chk = "This is a pen";
for(i = 0 ; i < nyuryoku.length() ; i ++ )
{
if ( i >= chk.length() )
{
break;
}
else if ( chk.charAt(i) == nyuryoku.charAt(i) )
{
atari++;
}
}
//==============================//
// ビューにフォワード //
//==============================//
// 結果の設定
session.setAttribute("msg","");
session.setAttribute("ritu",Integer.toString(atari*100/chk.length()));
// フォワード
getServletContext().getRequestDispatcher("/jsp/kekka.jsp").forward(request,response);
}
}
|