Login through Struts.
this is login action class.
package mypack;
import javax.servlet.ServletContext;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
public class LoginAction {
String name;
String password;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String execute(){
HttpServletRequest req=ServletActionContext.getRequest();
ServletContext ctx=ServletActionContext.getServletContext();
ServletResponse res=ServletActionContext.getResponse();
HttpSession session=req.getSession();
System.out.println(password);
return "ok";
}
}
<form action="login">//action name show in struts.xml
Name :<input type="text" name="name"><br/>
Password :<input type="password" name="password"><br/>
<input type="submit">
</form>
<struts>
<package name="demo">
<result-types>
<result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"></result-type>
</result-types>
<interceptors>
<interceptor name="params" class="com.opensymphony.xwork2.interceptor.ParametersInterceptor">
</interceptor>
</interceptors>
<action name="login" class="mypack.LoginAction">//class name
<interceptor-ref name="params"></interceptor-ref>//interceptor for processing of parameters
<result name="ok">/welcome.jsp</result>//class return ok then move to welcome.jsp
<result name="no">/error.jsp</result>//else error jsp.
</action>
</package>
</struts>
welcome.jsp
<%@ taglib uri="/struts-tags" prefix="s" %>
welcome...<s:property value="name"/>
error.jsp
Error...<br/>
<jsp:include page="index.jsp"></jsp:include>