0% found this document useful (0 votes)
81 views5 pages

Myactionaction - Java:: / Generated by Myeclipse Struts Template Path: Templates/Java/Javaclass - VTL

This document contains code for a Java class called MyactionAction that is a Struts action class. It contains an execute method that validates user login credentials by querying a database and returns a "success" or "failure" forward. It also includes the Login.jsp and Success.jsp pages used for the login form and success response along with the Struts configuration file Config.xml that maps the actions.

Uploaded by

seenu
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views5 pages

Myactionaction - Java:: / Generated by Myeclipse Struts Template Path: Templates/Java/Javaclass - VTL

This document contains code for a Java class called MyactionAction that is a Struts action class. It contains an execute method that validates user login credentials by querying a database and returns a "success" or "failure" forward. It also includes the Login.jsp and Success.jsp pages used for the login form and success response along with the Struts configuration file Config.xml that maps the actions.

Uploaded by

seenu
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

MyactionAction.

java:

/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.yourcompany.struts.action;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.yourcompany.struts.form.MyformForm;

import sun.misc.Request;

import java.sql.*;
import Mypack.*;

/**
* MyEclipse Struts
* Creation date: 10-30-2008
*
* XDoclet definition:
* @struts.action input="/Login.jsp" validate="true"
* @struts.action-forward name="success" path="/Success.jsp"
* @struts.action-forward name="failure" path="/Login.jsp"
redirect="true"
*/
public class MyactionAction extends Action {
String s,s1,s2;
Connection conn;
/*
* Generated Methods
*/

/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm
form,
HttpServletRequest request, HttpServletResponse
response)

{
MyformForm objMyformForm = (MyformForm)form;

String userName = objMyformForm.getUsername();


String password = objMyformForm.getPassword();

s=request.getParameter("t1");
s1=request.getParameter("t2");

DBconn d= new DBconn();


d.cc();

try
{
PreparedStatement ps=conn.prepareStatement("select
password from stud where userid =?,password=?");
ps.setString(1, s);
ResultSet rs=ps.executeQuery();
while(rs.next())
{
s2=rs.getString(1);
}

boolean status = true;


String forward = "";
if(status)
forward = "success";
else
forward = "failure";

return mapping.findForward(forward);

}
catch(Exception e)
{
e.printStackTrace();
}

// TODO Auto-generated method stub


return null;
}
}

Login.jsp:

<%@ page language="java" pageEncoding="ISO-8859-1"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>


<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


<html:html lang="true">
<head>
<html:base />

<title>Login.jsp</title>

<meta http-equiv="pragma" content="no-cache">


<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<html:form action="myaction.do" method="post" focus="login">
<table border="0">
<tr>
<td>Login:</td>
<td>
<html:text property="username" value="t1" />
</td>
</tr>
<tr>
<td>Password:</td>
<td><html:password property="password" value="t2"/></td>
</tr>
<tr>
<td colspan="2" align="center"><html:submit /></td>
</tr>
</table>
</html:form>
</body>
</html:html>

Success.jsp:

<%@ page language="java" pageEncoding="ISO-8859-1"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>


<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


<html:html lang="true">
<head>
<html:base />

<title>Success.jsp</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
This a struts page. <br>
</body>
</html:html>

Config.xml:

<?xml version="1.0" encoding="UTF-8"?>


<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD
Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-
config_1_2.dtd">

<struts-config>
<data-sources />
<form-beans >
<form-bean name="myformForm"
type="com.yourcompany.struts.form.MyformForm" />

</form-beans>

<global-exceptions />
<global-forwards />
<action-mappings >
<action
name="myformForm"
input="/Login.jsp"
path="/myaction"
type="com.yourcompany.struts.action.MyactionAction">
<forward name="success" path="/Success.jsp" />
<forward
name="failure"
path="/Login.jsp"
redirect="true" />
<forward
name="success"
path="/loginSuccess.jsp"
redirect="true" />

</action>

</action-mappings>
<message-resources
parameter="com.yourcompany.struts.ApplicationResources" />
</struts-config>

You might also like