Rochal Collins

Greenhorn
+ Follow
since Jul 31, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Rochal Collins

Nothing is happening. It should find the user and password in the database and forward to the user home page.
16 years ago
Hi. I'm trying to build a simple login page and registration page. People login through the login page. I use a DAO Factory to check the database to see if their username and password is in there. I'm having problems setting up the httpsession. I had it working with the Httpsession but now I have problems. I also want the person redirected to a welcome page if their username and password has been found in the database.

userservlet.java



Can someone tell me what I'm doing wrong???


[BSouther: Added UBB CODE tags]
[ September 26, 2007: Message edited by: Ben Souther ]
16 years ago
Thanks Merill. I figured it out early this morning. That was the problem!
16 years ago
I'm getting errors when I try to validate my application.

Here's my struts-config:

<action-mappings>
<action
path="/viewresume"
type="com.struts.resumeonline.SearchAction"
input="/viewresume.jsp"
name="searchForm"
scope="request"
validate="true">
<forward name="success" path="/viewresume" redirect="true" />

</action>
</action-mappings>

form:

public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request)
{
ActionErrors errors = new ActionErrors();
if (getEmail() == null || getEmail().length() < 1) {
errors.add("email", new ActionMessage("error.Search.email.missing"));
}
if (getPassword() == null || getPassword().length() < 1) {
errors.add("password", new ActionMessage("error.Search.password.missing"));
}

return errors;
}
applicationresources file:

# Resources for parameter 'com.struts.resumeonline.ApplicationResources'
# Project ResumeOnline
# Label Resouces
label.Search.email=Email
label.Search.password=Password


#Error Resources
error.Search.criteria.missing=Search Criteria Missing
error.Search.email.missing=Email Missing
errors.header=<font color="red"><cTypeface:Bold>Validation Error(s)</b></font><ul>
error.footer=</ul><hr width="100%" size="1" noshade="true">
errors.prefix=<li>
errors.suffix=</li>


Here's the errors:

org.apache.jasper.JasperException: org.apache.struts.action.ActionMessage
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:476)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:1012)
org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:980)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:255)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

root cause

java.lang.ClassCastException: org.apache.struts.action.ActionMessage
org.apache.struts.taglib.html.ErrorsTag.doStartTag(ErrorsTag.java:215)
org.apache.jsp.viewresume_jsp._jspx_meth_html_005ferrors_005f0(viewresume_jsp.java:357)
org.apache.jsp.viewresume_jsp._jspService(viewresume_jsp.java:106)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:1012)
org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:980)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:255)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

What am I doing wrong?
16 years ago
I have a form which the user enters their email address and password. When they click the submit button I want to pass their email address and password to another page. How can this be done?
[ August 13, 2007: Message edited by: Rochal Collins ]
16 years ago
I'm definitely confused about how dispatch action is supposed to work but I have a project I have to finish by Thursday. So I really don't have alot of time. The book for my class is not that helpful. I'm thinking that I will probably write different forms to handle the create and update functions rather than trying to do it all with one form. I'm not sure if this is the answer but I'll try it.
16 years ago
I would like to do that but I don't know how.

<action path="/index"
type="com.rochal.resume.SearchAction"
name="searchForm"
scope="request"
input ="/index.jsp"
parameter="ro"
validate="true">
<forward name="add" path="/create_resume" />
<forward name="view" path="/rochal" />
</action>
<action path="/rochal"
type="com.rochal.resume.SearchAction"
name="searchForm"
scope="request"
input ="/rochal.jsp">
<forward name="success" path="/myresume" />


</action>

This is what I have but its not working. I have 2 links on my index page. One to view and one to add. When the view is pressed it is forwarded to the rochal page. At that page the user is supposed to enter an email and password and then the page is forwarded to myresume. The create link should go to the create_resume page. What am I doing wrong?
16 years ago
I would like to get an item from my action class but I don't know the syntax for doing this. All I can is how to print out a collection of items using logic:iterate. Does anyone know how to print out just one item in their jsp???
16 years ago
I have a struts application. I want the user to login with an email address and password. After they log in I want to direct them to update page if their information is in the database to view their information OR to a create page to insert their information in the database. Can I do this? If so which dispatch action can be used? Thanks.
16 years ago
I've tried system.out.println statements and nothing prints out.

Here are my errors now:

SEVERE: Null component Catalina:type=DataSource,path=/MiniHR,host=localhost,class=javax.sql.DataSource,name="jdbc/TestDB"
SEVERE: Error creating form bean of class com.jamesholmes.miniHR.SearchForm
SEVERE: Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspException: Exception creating bean of class com.jamesholmes.miniHR.SearchForm: {1}
16 years ago
Nothing is happening.

Here's how I connect to the database:

public class ConnectionBean implements HttpSessionBindingListener{
private Connection connection;
private Statement statement;

private static final String driver="com.mysql.jdbc.Driver";
private static final String dbURL="jdbc:mysql://localhost:3306/employee?autoReconnect=true";
private static final String login="root";
private static final String password="";

public ConnectionBean(){
try{
Class.forName(driver);
connection=DriverManager.getConnection(dbURL, login, password);
statement=connection.createStatement();
}catch (ClassNotFoundException e){
System.err.println("ConnectionBean: driver unavailable.");
connection=null;
}
catch(SQLException e){
System.err.println("ConnectionBean: driver not loaded.");
connection=null;
}
}

public Connection getConnection(){
return connection;
}

public ResultSet executeQuery(String sql) throws SQLException{
return statement.executeQuery(sql);
}

protected void finalize(){
try{
connection.close();
}catch(SQLException e){

}
}

public void valueBound(HttpSessionBindingEvent event) {
System.err.println("ConnectionBean: in the valueBound method.");
try{
if (connection == null || connection.isClosed()){
connection = DriverManager.getConnection(dbURL,login,password);
statement=connection.createStatement();
}
}catch (SQLException e){
connection =null;
}
}

public void valueUnbound(HttpSessionBindingEvent event) {
try{
connection.close();
}catch(SQLException e){

}finally{
connection = null;
}
}

}

my action

EmployeeSearchService service = new EmployeeSearchService();
ArrayList results2;

SearchForm searchForm = (SearchForm) form;

results2=service.listEmp();
searchForm.setResults(results2);
return mapping.getInputForward();

jsp

<logic resent name="searchForm" property="results2">
<table>
<logic:iterate id="e" name="employees" >
<tr>
<td><bean:write name="e" property="name" /></td>
<td><bean:write name="e" property="ssn" /></td>
</tr>
</logic:iterate>
</table>
</logic resent>

EmployeeSearchService

public ArrayList listEmp() throws SQLException{
ArrayList listOfEmployees = new ArrayList();
ConnectionBean cnbean = new ConnectionBean();
String sql="select * from myemploy";
ResultSet rs = cnbean.executeQuery(sql);

while (rs.next()) {
Employee employee = new Employee();
employee.setName(rs.getString("name"));
employee.setSsn(rs.getString("ssn"));
listOfEmployees.add(employee);
//System.out.println(listOfEmployees.add(employee));
}
return listOfEmployees;
}



What am I doing wrong?? I don't even know if its connecting to the DB!
16 years ago
I thought I had it working but it isn't. How do I store the data from the database into a java bean list?
16 years ago
Figured it out! Thanks!
16 years ago
Ok so where would the
request.setAttribute("employee", listOfEmployee);

go?

Sorry I'm new to Struts.....the listOfEmployee would be equal to ???
16 years ago
Using Struts 1.3.8. Have successfully connected to the mysql database usind JNDI datasource. (i think) but I don't know how to print out the information from the database using the struts tlds. Any suggestions?
16 years ago