struts
<p>hi here is my code can you please help me to solve the exception</p>
<h1></h1>
<p><strong><em>login.html</em></strong></p>
<h1></h1>
<p><html>
<body></p>
<form action="login.do">
<pre>
user name:<input type="text" name="uname"/>
password:<input type="password" name="pass"/>
<input type="submit" value="login"/>
</pre>
</form>
<p></body></p>
<h1></html></h1>
<h1></h1>
<h1>***LoginAction.java***</h1>
<p>package com.st.struts;
import javax.servlet.http.*;
import org.apache.struts.action.*;
public class LoginAction extends Action
{
public ActionForward execute(ActionMapping am,ActionForm af,HttpServletRequest req,HttpServletResponse res)throws Exception
{</p>
<pre class="prettyprint"> UserForm uf=(UserForm)af;
String uname=uf.getUname();
String pass=uf.getPass();
LoginModel lm=new LoginModel();
String type=lm.validate(uname,pass);
if(type==null)
return am.findForward("notvalid");
return am.findForward("type");
}
</code></pre>
<p>}</p>
<h1></h1>
<p><hr />
<strong>LoginModel.java</strong>
<hr /></p>
<pre class="prettyprint">package com.st.struts;
import java.sql.*;
public class LoginModel
{
public String validate(String uname,String pass)
{ Connection con=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:online","system","manager");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select type from userdetails1 where username=\'"+uname+"\' and password=\'"+pass+"\'");
if(rs.next())
return rs.getString(1);
}//try
catch(Exception e)
{
e.printStackTrace();
}//catch
finally{
try{
con.close();
}catch(Exception e)
{
}//catch
}//finally
return null;
}
}
</code></pre>
<hr />
<h6>##########################################</h6>
<p><strong>UserForm.java</strong></p>
<h6>############################################</h6>
<pre class="prettyprint">package com.st.struts;
import javax.servlet.http.*;
import org.apache.struts.action.*;
class UserForm extends ActionForm
{
private String uname,pass;
public void setUname(String s)
{
uname=s;
}
public void setPass(String s)
{
pass=s;
}
public String getUname()
{
return uname;
}
public String getPass()
{
return pass;
}
public ActionErrors validate(ActionMapping am,HttpServletRequest req)
{
ActionErrors ae=new ActionErrors();
if(getUname()==null || getUname().equals(""))
ae.add("unameError", new ActionMessage("uname.empty"));
if(getPass()==null || getPass().equals(""))
ae.add("passError", new ActionMessage("pass.empty"));
else if(pass.length()<5)
ae.add("passError" ,new ActionMessage("pass.minlength"));
return ae;
}
}
</code></pre>
<h6>#############################################</h6>
<h1></h1>
<p>struts-config.xml</p>
<p>Blockquote</p>
<h1></h1>
<pre class="prettyprint"><struts-config>
<form-beans>
<form-bean name="userform" type="com.st.struts.UserForm"/>
</form-beans>
<action-mappings>
<action path="/login" type="com.st.struts.LoginAction" name="userform" scope="session" validate="true" input="/login.html">
<forward name="notvalid" path="/login.html"/>
<forward name="admin" path="/AdminHome.jsp"/>
<forward name="user" path="/UserHome.jsp"/>
</action>
</action-mappings>
</struts-config>
</code></pre>
<h1></h1>
<hr />
<p><strong>web.xml</strong></p>
<hr />
<pre class="prettyprint"> <web-app>
<servlet>
<servlet-name>as</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>as</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>login.html</welcome-file>
</welcome-file-list>
</web-app>
</code></pre>
<hr />
<p><hr />
<strong>AdminHome.jsp</strong></p>
<hr />
<pre class="prettyprint"><html>
<body>
welcome to the Admin home page<br/>
User name:<%= request.getParameter("uname")%>
</body>
</html>
</code></pre>
<hr />
<p><hr />
<strong>UserHome.jsp</strong></p>
<hr />
<pre class="prettyprint"><html>
<body>
welcome to the non Admin home page<br/>
User name:<%= request.getParameter("uname")%>
</body>
</html>
</code></pre>
<hr />
<hr />
<p>**and i created a table with the name userdetails1 and the columns are as shown below
column name=username(varchar2(20)
column namepassword varchar2(20)**</p>
<hr />
View Answers
February 16, 2011 at 3:29 PM
Related Tutorials/Questions & Answers:
Struts Struts How to retrive data from database by using
Struts STRUTSSTRUTS MAIN DIFFERENCES BETWEEN
STRUTS 1 AND
STRUTS 2
Advertisements
STRUTSSTRUTS MAIN DIFFERENCES BETWEEN
STRUTS 1 AND
STRUTS 2
StrutsStruts what is SwitchAction in
struts StrutsStruts how to learn
struts STRUTS STRUTS Request context in
struts?
SendRedirect () and forward how to configure in
struts-config.xml
strutsstruts in industry,
struts 1 and
struts 2. which is the best?
which is useful as a professuional
Have a look at the following link:
Struts Tutorials
StrutsStruts Tell me good
struts manual
strutsstruts what are the 4 methods of
struts framework
strutsstruts shopping cart project in
struts with oracle database connection shopping cart project in
struts with oracle database connection
Have a look at the following link:
Struts Shopping Cart using MySQL
Struts Struts When Submit a Form and while submit is working ,press the Refresh , what will happen in
Struts strutsstruts Hi
what is
struts flow of 1.2 version
struts?
i have
struts applicatin then from jsp page how
struts application flows
Thanks
Kalins Naik
Please visit the following link:
Struts Tutorial
struts struts how to write Dao to select data from the database
strutsstruts why doc type is not manditory in
struts configuration file
strutsstruts why doc type is not manditory in
struts configuration file
strutsstruts why doc type is not manditory in
struts configuration file
strutsstruts why doc type is not manditory in
struts configuration file
StrutsSetter methods of form bean class in
Struts applications who calls the setter methods of form bean class in
struts applications
Struts Struts What is called properties file in
struts? How you call the properties message to the View (Front End) JSP Pages
StrutsStruts Hi i am new to
struts. I don't know how to create
struts please in eclipse help me
struts struts Hi
how
struts flows from jsp page to databae and also using validation ?
Thanks
Kalins Naik
Struts Struts in
struts I want two struts.xml files. Where u can specify that xml files location and which tag u specified
strutsstruts which is the best book to study
struts on own?
please tell me
You can learn
struts through the following books:
1)Programming Jakarta
Struts By Chuck Cavaness
2)Professional Jakarta
Struts By James Goodwill
strutsstruts which is the best book to study
struts on own?
please tell me
You can learn
struts through the following books:
1)Programming Jakarta
Struts By Chuck Cavaness
2)Professional Jakarta
Struts By James Goodwill
StrutsStruts How
Struts is useful in application development? Where to learn
Struts?
Thanks
Hi,
Struts is very useful in writing web... performance Java web applications that runs on Java enabled application servers.
Struts strutsstruts how to start
struts?
Hello Friend,
Please visit the following links:ADS_TO_REPLACE_1
http://www.roseindia.net/
struts/
http... through which you can easily learn the
struts.
ThanksADS_TO_REPLACE_2
strutsstruts i have no any idea about struts.please tell me briefly about
struts?**
Hi Friend,
You can learn
struts from the given link:ADS_TO_REPLACE_1
Struts Tutorials
Thanks
strutsstruts hi
i would like to have a ready example of
struts using "action class,DAO,and services" for understanding.so please guide for the same.
thanks Please visit the following link:
Struts Tutorials
StrutsStruts Am newly developed
struts applipcation,I want to know how to logout the page using the strus
Please visit the following link:
Struts Login Logout Application
Struts Struts 1)in
struts server side validations u are using programmatically validations and declarative validations? tell me which one is better ?
2) How to enable the validator plug-in file
strutsstruts please send me a program that clearly shows the use of
struts with jsp
strutsstruts Hi,
1) can we write two controller classes in
struts strutsstruts Hi,... please help me out how to store image in database(mysql) using
struts strutsstruts how to generate bar code for continuous numbers in a loop using
struts ... or atleast for a given number
Struts Struts How will you retrieve a collection of records from business logic to presentation logic in framework
STRUTSSTRUTS 1)Have you used
struts tag libraries in your application?
2)What are the various types of tag libraries in
struts? Elaborate each of them?
3)How can you implement custom tag libraries in your application
strutsstruts hi
i would like to have a ready example of
struts using"action class,DAO,and services"
so please help me
strutsstruts Hi,
Here my quation is
can i have more than one validation-rules.xml files in a
struts application
strutsstruts we have the concept of jsp's and servlets right we can develop the web-pages each and everything then why what for
struts inturdouced
STRUTS STRUTS 1) Difference between Action form and DynaActionForm?
2) How the Client request was mapped to the Action file? Write the code and explain
STRUTS STRUTS Validation: user entered as 123.34567
I want the value as 123.34 once the user submits. How you will validate
struts technologies like servlets, jsp,and
struts.
i am doing one
struts application where i... the following links:
http://www.roseindia.net/
struts/StrutsCustomValidator.shtml
http://www.roseindia.net/
struts/addressstrutsvalidator.shtml
http
StrutsStruts What is
Struts?
Hi hriends,
Struts is a web page... web applications quickly and easily.
Struts combines Java Servlets, Java Server...,
Struts is a web page development framework and an open source software that helps
struts struts i have one textbox for date field.when i selected date from datecalendar then the corresponding date will appear in textbox.i want code for this in struts.plz help me
Struts - StrutsStruts examples for beginners
Struts tutorial and examples for beginners
StrutsStruts why in
Struts ActionServlet made as a singleton what is the specific reason how it useful in the webapplication development?
Basically in
Struts we have only Two types of Action classes.
1.BaseActions
StrutsStruts Why
struts rather than other frame works?
Struts is used into web based enterprise applications. Struts2 cab be used with Spring... by the application.
There are several advantages of
Struts that makes it popular
StrutsStruts I want to get the data from database into text box in a jsp page by using
struts and javascript If I click on go button it will display all the values and from that i need to select the required value and i should store