Вы находитесь на странице: 1из 6

Creating jsp page……

Action:

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

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.MybeanForm;

/**
* MyEclipse Struts
* Creation date: 10-21-2008
*
* XDoclet definition:
* @struts.action path="/myAction" name="mybeanForm" input="/Login.jsp"
scope="request" validate="true"
* @struts.action-forward name="failure" path="/Login.jsp" redirect="true"
* @struts.action-forward name="sucess" path="/sucess.jsp"
*/
public class MyActionAction extends Action {
/*
* 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) {
MybeanForm mybeanForm = (MybeanForm) form;
String log=mybeanForm.getUserid();
String pwd=mybeanForm.getPassword();
String s="java";
if(log.equals(s)&&(pwd.equals(s)))
{
return mapping.findForward("sucess");
}else
return mapping.findForward("failure");
}

***********************************************

Login Page..

<%@ 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" method="post" focus="login">
<table border="0">
<tr>
<td>Login:</td>
<td><html:text property="userid" /></td> // want to change
the property
</tr>
<tr>
<td>Password:</td>
<td><html:password property="password" /></td>
</tr>
<tr>
<td colspan="2" align="center"><html:submit /></td>
</tr>
</table>
</html:form>
</body>
</html:html>

********************************

Struct1 prg jsp… with database connection…

Action page…..

/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.yourcompany.struts.action;
import strutdatabase.*;
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.*;

import java.io.DataInputStream;
import java.sql.*;

/**
* MyEclipse Struts
* Creation date: 10-20-2008
*
* XDoclet definition:
* @struts.action validate="true"
* @struts.action-forward name="success" path="/success.jsp"
* @struts.action-forward name="failure" path="/Home.jsp" redirect="true"
*/
public class ActiononeAction extends Action
{
Connection con;
String a,a1;
/*
* 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)
{

MystrutjspForm mf = new MystrutjspForm();

Dbconn c= new Dbconn();


con=c.connv();
String usrid= mf.getUserid();
String pwd=mf.getPassword();
try
{
PreparedStatement pstmt= con.prepareStatement("select * from
stud where username=?");

pstmt.setString(1,usrid);
ResultSet rs=pstmt.executeQuery();

while(rs.next())
{
a=rs.getString(1);
a1=rs.getString(2);
}
rs.close();
pstmt.close();
con.close();
}
catch(SQLException se)
{
}
if(usrid.equals(a) && (pwd.equals(a1)))
return mapping.findForward("success");
else
return mapping.findForward("failure");
//return null;
}

// TODO Auto-generated method stub

Database connection page….

package strutdatabase;
import java.sql.*;

public class Dbconn


{
Connection conn;
public Connection connv()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn= DriverManager.getConnection("Jdbc:Odbc:check");
}
catch(ClassNotFoundException ce )
{

}
catch(SQLException se)
{
}
return conn;

Login page….

<%@ 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>Home.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="/actionHome" method="post" focus="login"> // we
have to mention path
<table border="0">
<tr>
<td>Login:</td>
<td><html:text property="userid" value=""/></td> //we have to
set property
</tr>
<tr>
<td>Password:</td>
<td><html:password property="password" value="" /></td>
</tr>
<tr>
<td colspan="2" align="center"><html:submit /></td>
</tr>
</table>
</html:form>
</body>
</html:html>

Вам также может понравиться