This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes help with login program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "help with login program" Watch "help with login program" New topic
Author

help with login program

theju nagral
Greenhorn

Joined: Mar 12, 2010
Posts: 5
struct-config.xml

<struts-config>

<form-beans>

<form-bean name="loginForm"
type="app.LoginForm"/>

</form-beans>

<global-forwards>
<forward name="welcome"
path="/Welcome.do"/>

</global-forwards>


<action-mappings>
<action path="/Welcome"
forward="/pages/Home.jsp"/>

<action path="/login"
type="app.LoginAction"
name="loginForm"
scope="request"
validate="true"
input="/pages/Login.jsp">
<forward name="success"
path="/pages/success.jsp"/>
</action>

</action-mappings>

<controller
processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>



<message-resources parameter="MessageResources" />


<plug-in className="org.apache.struts.tiles.TilesPlugin" >
<set-property property="definitions-config"
value="/WEB-INF/tiles-defs.xml" />

<set-property property="moduleAware" value="true" />
</plug-in>

</struts-config>
---------------------------------------------------
login.jsp

<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<HTML>
<HEAD>
<TITLE>Sign in, Please!</TITLE>
</HEAD>
<BODY>
<html:errors/>
<html:form action="/login">
<TABLE border="0" width="100%">
<TR>
<TH align="right"><FONT SIZE="5">Username:</FONT></TH>
<TD align="left"><html:text property="username"/></TD>
</TR>
<TR>
<TH align="right"><FONT SIZE="5">Password:</FONT></TH>
<TD align="left"><html:password property="password"/></TD>
</TR>
<TR>
<TD align="right"><html:submit/></TD>
<TD align="right"><html:reset/></TD>
</TR>
</TABLE>
</html:form>
</BODY>
</HTML>
--------------------------------------------------------------------------------------
success.jsp

<html>
<body>
<h1> successfully logged in</h1>
</body>
</html>
-------------------------------------------------------------------------------
login form

package app;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public final class LoginForm extends ActionForm {
private String password = null;
private String username = null;

public String getUsername() {
return (this.username);
}
public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return (this.password);
}
public void setPassword(String password) {
this.password = password;
}

}

}
---------------------------------------------------------------------
login action

package app;


import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
//import org.apache.struts.action.ActionServlet;

import app.dao.mydao.dao;


public final class LoginAction extends Action {

public boolean isUserLogin(String username, String password)
{
dao t2=new dao();
String pass=null;
try
{
pass=t2.select(username);
}
catch (SQLException e)
{
e.printStackTrace();
}

if (password.equals(pass))
return true;
else
return false;
}



public ActionForward perform(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {

String username = ((LoginForm) form).getUsername();
String password = ((LoginForm) form).getPassword();



boolean validated = false;
try
{
validated = isUserLogin(username,password);
}

catch (Exception e) {
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("error.logon.connect"));
saveErrors(request,errors);
return (new ActionForward(mapping.getInput()));
}

return (mapping.findForward("success"));

}

}
------------------------------------------------
when i try to login it is not going to success.jsp page. instead it is showing me a blank page with url
http://localhost:8080/oxy/login.do

is there anything wrong in my program

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read.

You can edit your post by using the button.

To answer your question, yes, if you're expecting output and your page is blank, something is probably wrong with your program.

Why are you using the TilesRequestProcessor if you're not using any Tiles?
theju nagral
Greenhorn

Joined: Mar 12, 2010
Posts: 5
Here is the code

struct-config.xml

---------------------------------------------------
login.jsp

--------------------------------------------------------------------------------------
success.jsp

-------------------------------------------------------------------------------
login form

---------------------------------------------------------------------
login action

------------------------------------------------
when i try to login it is not going to success.jsp page. instead it is showing me a blank page with url
http://localhost:8080/oxy/login.do

is there anything wrong in my program

========================
i am using tiles in my program

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Do you really not indent your code?
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
Hi,

you are using struts 1.0, right?
check your server log file what it shows...

Thanks,
Shailesh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help with login program
 
Similar Threads
problem in Developing Struts small Apllication
ServletException in:/pages/logon.jsp] Cannot retrieve definition for form bean null'
simple login n home(w/ iterate tag)
Struts 1.1 problem with form validation
Struts Error