Академический Документы
Профессиональный Документы
Культура Документы
Output:
JAVA file:
import
import
import
import
import
import
java.io.IOException;
java.io.PrintWriter;
javax.servlet.ServletException;
javax.servlet.http.HttpServlet;
javax.servlet.http.HttpServletRequest;
javax.servlet.http.HttpServletResponse;
Output:
JAVA file:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class calc extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
int a=Integer.parseInt(request.getParameter("no1"));
int b=Integer.parseInt(request.getParameter("no2"));
int c=0;
String op=request.getParameter("btn");
if(op.equals("+")) c=a+b;
if(op.equals("-")) c=a-b;
if(op.equals("*")) c=a*b;
if(op.equals("/")) c=a/b;
out.println(a+op+b+"="+c);
}
}
}
Output:
1)Addition:
3)multiplication:
2)Subtraction:
4)division:
</html>
JAVA file:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class fact extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try{
int a=Integer.parseInt(request.getParameter("no"));
int fact=1;
for(int i=1;i<=a;i++)
{
fact=fact*i;
}
out.println("factorial of "+a+" is "+fact);
}
catch(Exception e)
{
out.println("ERROR:"+e.getMessage());
}
}
}
Output:
Output:
JAVA file:
import
import
import
import
import
import
import
java.io.IOException;
java.io.PrintWriter;
javax.servlet.ServletException;
javax.servlet.annotation.WebServlet;
javax.servlet.http.HttpServlet;
javax.servlet.http.HttpServletRequest;
javax.servlet.http.HttpServletResponse;
{
out.println("ERROR:"+e.getMessage());
}
}
}
Output:
Output:
JAVA file:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import
import
import
import
javax.servlet.annotation.WebServlet;
javax.servlet.http.HttpServlet;
javax.servlet.http.HttpServletRequest;
javax.servlet.http.HttpServletResponse;
Output:
PRACTICAL : 2
Q.1 write a servlet program to design a Question
Answer Formate.
Source Code:
HTML File:
<html>
<head>
<title>Question Answer formate</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form method="get" action="Qa">
<center><h1>MULTIPLE CHOICE QUESTIONS.</h1></center>
1.what is fullform of JSF<br>
<input type="radio" name="f1" value="1">
Java server pages<br>
<input type="radio" name="f1" value="2">
Java servlet fact<br>
<input type="radio" name="f1" value="3">
JJ SS FF<br>
<input type="radio" name="f1" value="4">
none of these.<br><br>
2.what is the fullform of CGI?<br>
<input type="radio" name="f2" value="1">
Comman Gateway Integrity<br>
<input type="radio" name="f2" value="2">
Comman Group Interface<br>
<input type="radio" name="f2" value="3">
Comman GateWay Interface<br>
<input type="radio" name="f2" value="4">
None of these<br><br>
3.Servlet is a ......<br>
Output:
JAVA file:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Qa extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
int r=0;
int a=Integer.parseInt(request.getParameter("f1"));
int b=Integer.parseInt(request.getParameter("f2"));
int c=Integer.parseInt(request.getParameter("f3"));
int d=Integer.parseInt(request.getParameter("f4"));
int e=Integer.parseInt(request.getParameter("f5"));
if(a==2)r++;
if(b==3)r++;
if(c==1)r++;
if(d==1)r++;
if(e==4)r++;
out.println("total score is "+r);
} finally {
out.close();
}
}
}
PRACTICAL : 3
Q.2write a java program to retrieve data from database using
SQL statement.
package jdbc;
import java.sql.*;
public class JDBC {
public static void main(String[] args)throws SQLException {
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/mydb","root","tiger");
Statement st=con.createStatement();
String sql="select * from dept";
ResultSet rs=st.executeQuery(sql);
ResultSetMetaData md=rs.getMetaData();
System.out.print("\n");
int n=md.getColumnCount();
for(int i=1;i<=n;i++)
System.out.print(md.getColumnName(i)+"\t");
System.out.print("\n");
if(!(rs.isBeforeFirst()))
{
System.out.print("no matching records\t\t");
System.exit(0);
}
else
{
while(rs.next())
{
System.out.print(rs.getInt(1)+"\t");
System.out.print(rs.getString(2)+"\t\t");
System.out.print(rs.getString(3)+"\n");
}
}
con.close();
}
catch(Exception e)
{
System.out.print("Error: "+e.getMessage());
}
}
}
OUTPUT:
Output:
int dept_no=Integer.parseInt(br.readLine());
System.out.println("enter DEPT_NAME:");
String dept_name=br.readLine();
System.out.println("enter DEPT_LOC:");
String dept_loc=br.readLine();
ps.setString(1, dept_name);
ps.setString(2, dept_loc);
ps.setInt(3, dept_no);
ps.executeUpdate();
System.out.println("DATA UPDATED.....");
}
catch(Exception e)
{
System.out.print("ERROR :"+e.getMessage());
}
}
OUTPUT:
int dept_no=Integer.parseInt(br.readLine());
ps.setInt(1, dept_no);
ps.executeUpdate();
System.out.println("ROW DELETED.....");
}
catch(Exception e)
{
System.out.print("ERROR :"+e.getMessage());
}
}
}
OUTPUT:
OUTPUT:
JSP File:
<%@ page contentType="text/html" pageEncoding="UTF-8" %>
<%@page import= "java.sql.*" %>
<html>
<body>
<%
try{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/registration","root","");
PreparedStatement ps=con. prepareStatement("insert into user
values(?,?,?)");
int regno=Integer.parseInt(request.getParameter("no"));
String reg_name=request.getParameter("name");
String email_add=request.getParameter("email");
out.println("<br>REGISTRATION NO :"+regno);
out.println("<br>NAME :"+reg_name);
out.println("<br>EMAIL ADDRESS :"+email_add);
ps.setInt(1,regno);
ps.setString(2,reg_name);
ps.setString(3,email_add);
ps.executeUpdate();
out.println("<br> Data added....");
}
catch(Exception e)
{
out.println("not possible to add the record"+e.getMessage());
}
%>
00</body>
</html>
OUTPUT:
PRACTICAL 4
Q.1 Develop a JSP application to authenticate user login as per
the registration details.
Source Code:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h2>WELCOME USER</h2>
<%=request.getParameter("uname")%>
</body>
</html>
OUTPUT:
Valid password:
Invalid password:
</body>
</html>
OUTPUT:
Practical : 5
Q.1 create an applet that can handle action
event(button),when an event occurs display the
respective result on the applet window.
Source code:
File name:button.java
package applet184;
importjava.awt.*;
importjava.awt.event.*;
importjava.applet.*;
/*<applet code="Applet184" width="300" height="400">
* </applet>
*/
public class Applet184 extends Applet implements ActionListener
{
String msg="";
Button b1,b2;
public void init()
{
b1=new Button("hello");
b2=new Button("hi");
add(b1);
add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e)
{
String st=e.getActionCommand();
if(st.equals("hello"))msg="hello buton pressed";
else if(st.equals("hi"))msg="hi button pressed";
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg,100,100);
}
}
Output:
Source code:
File name:button.java
packageAppletex;
importjava.applet.Applet;
importjava.awt.Button;
importjava.awt.Color;
importjava.awt.GridLayout;
importjava.awt.TextField;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.awt.event.TextEvent;
importjava.awt.event.TextListener;
public class appletx2 extends Applet implements ActionListener, TextListener{
String s,s1,s2,s3,s4;
Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b0;
Button add,sub,eq,c1,mul,div;
TextField t1;
inta,b,c;
public void init() {
t1=new TextField(10);
b1=new Button("1");
b2=new Button("2");
b3=new Button("3");
b4=new Button("4");
b5=new Button("5");
b6=new Button("6");
b7=new Button("7");
b8=new Button("8");
b9=new Button("9");
b0=new Button("0");
add=new Button("+");
sub=new Button("-");
mul=new Button("*");
div=new Button("/");
eq=new Button("=");
c1=new Button("clear");
GridLayoutgb=new GridLayout(4,5);
setLayout(gb);
add(t1);
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
add(b7);
add(b8);
add(b9);
add(b0);
add(add);
add(sub);
add(mul);
add(div);
add(eq);
add(c1);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b0.addActionListener(this);
add.addActionListener(this);
mul.addActionListener(this);
div.addActionListener(this);
eq.addActionListener(this);
c1.addActionListener(this);
paint();
}
public void paint()
{
setBackground(Color.green);
}
public void actionPerformed(ActionEvent e)
{
s=e.getActionCommand();
if(s.equals("0")||s.equals("1")||s.equals("2")||s.equals("3")||s.equals("4")
||s.equals("5")||s.equals("6")||s.equals("7")||s.equals("8")||s.equals("9")||
s.equals("0"))
{
s1=t1.getText()+s;
t1.setText(s1);
}
if(s.equals("+"))
{
s2=t1.getText();
t1.setText("");
s3="+";
}
if(s.equals("-"))
{
s2=t1.getText();
t1.setText("");
s3="-";
}
if(s.equals("*"))
{
s2=t1.getText();
t1.setText("");
s3="*";
}
if(s.equals("/"))
{
s2=t1.getText();
t1.setText("");
s3="/";
}
if(s.equals("="))
{
s4=t1.getText();
a=Integer.parseInt(s2);
b=Integer.parseInt(s4);
if(s3.equals("+"))
c=a+b;
if(s3.equals("-"))
c=a-b;
t1.setText(String.valueOf(c));
}
if(s.equals("clear"))
{
t1.setText("");
}
}
public void textValueChanged(TextEvent e)
{
}
}
Output :
import javax.swing.event.ListSelectionListener;
super("product details");
c=getContentPane();
list=new JList(prod);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addListSelectionListener(this);
lbl1= new JLabel();
jsp=new JScrollPane(list);
jsp.setBounds(200,200,100,135);
c.add(jsp);
lbl1.setBounds(200,200,100,135);
c.add(lbl1);
setSize(400,400);
setDefaultCloseOperation(3);
setVisible(true);
}
public static void main(String[] args) {
new stationary();
}
}
}
OUTPUT:
SOURCE CODE:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*; public class employee extends JFrame implements
ActionListener
{
JTable jt;
DefaultTableModel dtm;
JScrollPane jsp;
JLabel l1,l2,l3;
JTextField t1,t2,t3;
employee()
{ super("employee table");
Object[][]data=null;
String[] head={"employee no","name","age"};;
dtm=new DefaultTableModel(0,3);
dtm.setDataVector(data,head);
jt=new JTable(dtm);
jt.setGridColor(Color.RED);
jt.setRowSelectionAllowed(true);
jsp=new JScrollPane(jt);
JPanel p1=new JPanel();
p1.add(jsp);
l1=new JLabel("employee no.:");
l2=new JLabel("Name:");
l3=new JLabel("Age:");
t1=new JTextField(5);
t2=new JTextField(13);
t3=new JTextField(3);
JButton b1=new JButton("ADD");
b1.addActionListener(this);
JPanel p2=new JPanel();
p2.add(l1);
p2.add(t1);
p2.add(l2);
p2.add(t2);
p2.add(l3);
p2.add(t3);
p2.add(b1);
Container c=getContentPane();
c.add(p1,BorderLayout.NORTH);
c.add(p2,BorderLayout.CENTER);
setSize(600,600);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e) {
int empno=Integer.parseInt(t1.getText());
String name=t2.getText();
int age=Integer.parseInt(t3.getText());
Object[] data={empno,name,age};
dtm.addRow(data);
t1.setText("");
t2.setText("");
t3.setText("");
}
public static void main(String[] args) {
new employee();
}
}
OUTPUT:
PRACTICAL 7
Write a java program using SplitPane to demonstrate a screen
divide into two parts,one part contains names of planet and
case 4:lb1.setIcon(img4);break;
case 5:lb1.setIcon(img5);break;
case 6:lb1.setIcon(img6);break;
case 7:lb1.setIcon(img7);break;
case 8:lb1.setIcon(img8);break;
case 9:lb1.setIcon(img9);break;
default:lb1.setText("image not found.");
}
}
public static void main(String[] args)
{
new Planet();
}
}
OUTPUT:
OUTPUT:
OUTPUT:
PRACTICAL 8
1)create a JSF application for inventory of product.
MYSQL COMMAND:
INDEX.XHTML:
SUCCESS.XHTML:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Product Form</title>
</h:head>
<h:body>
Product Details Added Successfully
</h:body>
</html>
ERROR.XHTML:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Product Form</title>
</h:head>
<h:body>
Error in data entry
</h:body>
</html>
BEAN.JAVA:
package bean;
import java.sql.*;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean
@RequestScoped
public class bean
{
private int pcode;
private String pname;
public int getPcode()
{
return pcode;
}
public void setPcode(int pcode)
{
this.pcode = pcode;
}
public String getPname()
{
return pname;
}
public void setPname(String pname)
{
this.pname = pname;
}
public String add()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/prod133","root","tiger");
PreparedStatement ps=con.prepareStatement("insert into product133 values(?,?)");
ps.setInt(1,pcode);
ps.setString(2,pname);
ps.executeUpdate();
return "yes";
}
catch(Exception e)
{
return "no";
}
}
}
FACES-CONFIG.XML:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<navigation-rule>
<from-view-id>/index.xhtml</from-view-id>
<navigation-case>
<from-outcome>yes</from-outcome>
<to-view-id>/success.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>no</from-outcome>
<to-view-id>/error.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>b1</managed-bean-name>
<managed-bean-class>bean.bean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config>
OUTPUT:
INDEX1.XHTML:
WELCOME.XHTML:
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/log133","root","tiger");
PreparedStatement ps=con.prepareStatement("select * from login133 where
name=? and pass=?");
ps.setString(1,name);
ps.setString(2,pass);
ResultSet rs=ps.executeQuery();
if(rs.isBeforeFirst())
return "welcome";
else
return "error";
}
catch(Exception e)
{
return "error";
}
}
public String back()
{
return "index1";
}
}
FACES-CONFIG.XML:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<navigation-rule>
<from-view-id>/index1.xhtml</from-view-id>
<navigation-case>
<from-outcome>welcome</from-outcome>
<to-view-id>/welcome.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>error</from-outcome>
<to-view-id>/error1.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/error1.xhtml</from-view-id>
<navigation-case>
<from-outcome>index</from-outcome>
<to-view-id>/index1.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>b1</managed-bean-name>
<managed-bean-class>bean1.bean1</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config>
OUTPUT:
PRACTICAL 9
Q 1) develop a stateless session bean for Room Reservation
System.Creates an application to accept number of rooms for
CHECKIN and CHECKOUT from the client ,according to that
changes are made in Database by using EJB.
Mysql command:
{
return 0;
}
}
}
EJB.roombeanLocal;
java.io.IOException;
java.io.PrintWriter;
javax.ejb.EJB;
javax.servlet.ServletException;
javax.servlet.annotation.WebServlet;
javax.servlet.http.HttpServlet;
javax.servlet.http.HttpServletRequest;
javax.servlet.http.HttpServletResponse;
res=obj.checkout(no);
if(res==1)
out.println(no+"room check out");
}
if(res==0)
out.println("not possible to do CHECK IN/OUT");
out.println("<br><br><a href=room.html>BACK </a>");
} finally {
out.close();
}
}
}
Output:
1.CHECKIN
2.CHECKOUT
Practical No. 10
Hibernate Feedback of Website Visitor
Program :MySql Command :1) create database db;
2) use db;
3) create table guestbook(no int primary key auto_increment, name varchar(20),msg
varchar(100), dt varchar(40));
File name - Guestbook.java
package hibernate;
public class Guestbook implements java.io.Serializable {
public Guestbook() {
}
}
public String getMsg() {
return this.msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public String getDt() {
return this.dt;
}
public void setDt(String dt) {
this.dt = dt;
}
}
</session-factory>
</hibernate-configuration>
<head>
<title>Guest Book</title>
</head>
<body>
Guest Book <hr> <br> <br>
<form action="guestbookview.jsp" method="post">
Name <input type="text" name="name" maxlength="20"> <br>
Message <textarea rows="5" cols="40" maxlength="100"
name="msg"></textarea>
<br> <input type="submit" value="submit">
</form>
</body>
</html>
<%!
SessionFactory sf;
org.hibernate.Session ss;
List<hibernate.Guestbook> gbook;
%>
<%
sf = new Configuration().configure().buildSessionFactory();
ss= sf.openSession();
Transaction tx=null;
Guestbook gb=new Guestbook();
try
{
tx=ss.beginTransaction();
String name=request.getParameter("name");
String msg=request.getParameter("msg");
String dt=new java.util.Date().toString();
gb.setName(name);
gb.setMsg(msg);
gb.setDt(dt);
ss.save(gb);
tx.commit();
}
catch(Exception e){ out.println("Error"+e.getMessage()); }
try
{
ss.beginTransaction();
gbook=ss.createQuery("from Guestbook").list();
}
catch(Exception e){ }
%>
<html>
<head>
<title>Guest View</title>
</head>
<body>
Guest View
Click here to go <a href="index.jsp"> BACK </a>
<br><br>
<%
Iterator it=gbook.iterator();
while(it.hasNext())
{
Guestbook each=(Guestbook)it.next();
out.print(each.getDt()+" ");
out.print(each.getName()+"<br>");
out.print(each.getMsg()+"<br><br>");
}
%>
</body>
</html>
Output :-
Steps:
Practical No. 11
Struts E-mail Validator
AIM
Develop a simple Struts Application to Demonstrate E-mail Validator.
Description
I.
II.
III.
IV.
B. Mapping file
Select the web.xml file from the configuration files
Click the pages tag
Select the welcome files (login.jsp)
Pracs11:struts:
Login.jsp:
<html>
<head>
<title>Login Page</title>
</head>
<body>
<form name="login" action="login.do">
<br>Username
<input type="text" name="username" value="">
<br>Email ID
<input type="text" name="email" value="">
<br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
Success.jsp:
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<html>
<head>
<title>Success Page</title>
</head>
<body>
Email Validation is done...
<struts-config>
<form-beans>
<form-bean name="bean1" type="com.myapp.struts.bean1"/>
</form-beans>
<global-exceptions>
</global-exceptions>
<global-forwards>
<forward name="welcome" path="/Welcome.do"/>
</global-forwards>
<action-mappings>
<action name="bean1" path="/login" scope="request"
type="com.myapp.struts.loginaction1" validate="false">
<forward name="login" path="/login.jsp"/>
<forward name="success" path="/success.jsp"/>
<forward name="failure" path="/failure.jsp"/>
</action>
<action path="/Welcome" forward="/welcomeStruts.jsp"/>
</action-mappings>
<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>
<message-resources parameter="com/myapp/struts/ApplicationResource"/>
</struts-config>
Bean1.java(form bean)
package com.myapp.struts;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
public class bean1 extends org.apache.struts.action.ActionForm {
}
Loginaction1.java
package com.myapp.struts;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
bean1 b1=(bean1)form;
String m=b1.getEmail();
if (m == null || m.equals("") || m.indexOf("@") == -1) {
return mapping.findForward(FAILURE);
}
else{
return mapping.findForward(SUCCESS);
}
}
}
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<jsp-config>
<taglib>
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
Output: