View Single Post
  #19 (permalink)  
Old 04-09-2008, 01:22 PM
lema lema is offline
Member
 
Join Date: Apr 2008
Posts: 38
lema is on a distinguished road
i change login page to jsp, and it is like this

<form name="LoginServlet" method="post" action="${pageContext.request.contextPath}/LoginServlet.class">

<table>
<tr>
<td>Username: </td>
<td align = "left" width="20"><input name="username" type="text" size="40"></input></td>
</tr>
<tr>
<td>Password: </td>
<td align = "left" width="20"><input name="password" type="password" size="40"></input></td>
</tr>
<tr><td>
<input type="submit" name="enter" value="Enter SMD"></input>
</td></tr>
</table>
</form>

in LoginServlet.java there the code snippet looks like


public class LoginServlet extends RemoteServiceServlet
implements LoginService
{
public LoginServlet() {
super();
}

static public Context getInitialContext() throws Exception
{
java.util.Properties p = new java.util.Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
p.put(Context.URL_PKG_PREFIXES, "jboss.namingrg.jnp.interfaces");
p.put(Context.PROVIDER_URL, "localhost:1099");
return new javax.naming.InitialContext(p);
}

private static Object findObject(String name) {
try {
Context ctx = getInitialContext();
return ctx.lookup(name);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

public void checkLogin(String u, String p) throws Exception {
LoginRemote loginRemote =(LoginRemote)
findObject("example.server/login/remote");



SmdUser smdUser = loginRemote.checkLogin(u, p);
if (smdUser != null) {
this.getThreadLocalRequest().getSession(true).setA ttribute("user", smdUser);
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher("http://111.111.11.111:8080/example/Application.html");
dispatcher.forward(getThreadLocalRequest(), getThreadLocalResponse());

} else {
Window.alert("You are not SMD member!");

}

}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
processRequest(request, response);
}

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String actionName = "";
String pathInfo = request.getPathInfo();
System.out.println("PATH INFO IS: " + pathInfo);
String destinationPage = "/smderror.jsp";

if (pathInfo != null) {
actionName = pathInfo.substring(1); // Get the action name from the HTTP Request.
System.out.println("ACTION NAME IS: " + actionName);
}


// perform action
if("loginServlet".equals(actionName))
{
String[] username = request.getParameterValues("username");
String[] password = request.getParameterValues("password");
String u = username[0];
String p = username[0];
try {
checkLogin(u, p);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else
{
String errorMessage = "[" + actionName + "] is not a valid action.";
request.setAttribute("/smderror.jsp", errorMessage);
}


// Redirect to destination page.
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(destinati onPage);

dispatcher.forward(request, response);
}

}
Reply With Quote