サーブレットを使用して以下のアプリケーションを開発しましたが、ユーザー名とパスワードを入力しても 2 番目のページが表示されません..アドバイスしてください...
最初のサーブレットは..
package Demo;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SendRedirectServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse
response)throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
String name = request.getParameter("username");
String password = request.getParameter("password");
if(name.equals("james")&& password.equals("abc")){
response.sendRedirect("Demo/ValidUserServlet");
}
else{
pw.println("u r not a valid user");
}
}
}
2 番目のサーブレットは ..
package Demo;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ValidUserServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse
response)throws ServletException, IOException {
PrintWriter pw = response.getWriter();
pw.println("Welcome to roseindia.net " + " ");
pw.println("how are you");
}
}
login.html ファイルは...
<html>
<head>
<title>New Page 1</title>
</head>
<body>
<form method="post" action="SendRedirectServlet">
<p>Enter your name
<input type="text" name="username" size="20"/></p>
<p>Enter your password <input type="text" name="password"
size="20"/></p>
<p>
<input type="submit" value="Submit" name="B1"/></p>
</form>
</body>
</html>
そして最後にweb.xmlは..
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Zulfiqar</servlet-name>
<servlet-class>Demo.SendRedirectServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Zulfiqar</servlet-name>
<url-pattern>/SendRedirectServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Hello</servlet-name>
<servlet-class>Demo.ValidUserServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/ValidUserServlet</url-pattern>
</servlet-mapping>
</web-app>
最初のページ (http://localhost:9050/SendRedirect/Login.html) で名前とパスワードを入力しますが、送信ボタンをクリックすると次のエラーが表示されます。
INFO: Marking servlet Zulfiqar as unavailable
15 Jul, 2012 8:14:56 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet Zulfiqar
java.lang.ClassNotFoundException: Demo.SendRedirectServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:525)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:507)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:124)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1136)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:857)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
15 Jul, 2012 8:20:26 PM org.apache.catalina.core.StandardWrapperValve invoke
INFO: Servlet Zulfiqar is currently unavailable
提案された変更を行いましたが、まだこのエラーが発生しています...
INFO: Marking servlet Zulfiqar as unavailable
15 Jul, 2012 9:11:48 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet Zulfiqar
java.lang.ClassNotFoundException: Demo.SendRedirectServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:525)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:507)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:124)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1136)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:857)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
15 Jul, 2012 10:06:42 PM org.apache.catalina.core.StandardWrapperValve invoke
INFO: Servlet Zulfiqar is currently unavailable