Myactionaction - Java:: / Generated by Myeclipse Struts Template Path: Templates/Java/Javaclass - VTL
Myactionaction - Java:: / Generated by Myeclipse Struts Template Path: Templates/Java/Javaclass - VTL
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;
s=request.getParameter("t1");
s1=request.getParameter("t2");
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);
}
return mapping.findForward(forward);
}
catch(Exception e)
{
e.printStackTrace();
}
Login.jsp:
<title>Login.jsp</title>
</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:
<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:
<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>