Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8449457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:42:45+00:00 2026-06-10T10:42:45+00:00

i’ve done a struts2 login action using mysql database which is as shown below.

  • 0

i’ve done a struts2 login action using mysql database which is as shown below.
for the initial login action i’m using LoginActionBean where i checks the username and password. After loging into the Main page there i need to get the team details again from the database. For that i used jsp scriplet tags. Can anyone tell me another way in which to access the team details from the database through javabeans (not through LoginActionBean) and without using the jsp scriplets.

login.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
</head>
<body>
    <s:form action="log">
    <s:textfield label="USERNAME" name="uname"/>
    <s:password label="PASSWORD" name="pass"/>
    <s:submit label="SUBMIT"/>
    </s:form>
</body>
</html>

Main.jsp

<%@page import="java.sql.ResultSet"%>
<%@page import="DbCon.DataConnection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Welcome to Employee Home!</h1>
        SELECT A TEAM:<select name="team">
            <%
             DataConnection db=new DataConnection();
             ResultSet rs=db.exeQuery("select * from team");
             while(rs.next())
                 {
            %>
            <option value="<%=rs.getString("teamname")%>" ><%=rs.getString("teamname")%></option>
            <%
            }
            %>
        </select>
    </body>
</html>

struts.xml

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

<struts>
    <constant name="struts.devMode" value="true" />
    <package name="default" extends="struts-default">
        <action name="log" class="login.Action.LoginActionBean" >
         <result name="success">/Main.jsp</result>
         <result name="error">/login.jsp</result>
        </action>
    </package>
</struts>

DataConnection.java

package DbCon;
import java.io.FileInputStream;
import java.sql.*;
public class DataConnection
{
    Connection con;
    Statement stmt;
    PreparedStatement pstmt;
    ResultSet rs=null;
    public DataConnection()
    {
        try
        {
            Class.forName("com.mysql.jdbc.Driver");
            con=DriverManager.getConnection("jdbc:mysql://localhost/test","root","");
            stmt=con.createStatement();
            con.setAutoCommit(false);
        }catch(Exception e){
            System.out.println("Err in constructor"+e);
        }
    }
    public ResultSet exeQuery(String query)
    {
        try
        {
           // con.commit();
            rs=stmt.executeQuery(query);
        }catch(Exception e){System.out.println(e);}
        return rs;
    }
    public int exeUpdate(String query)
    {
        int i = 0;
        try
        {
            //con.commit();
            i=stmt.executeUpdate(query);
            con.commit();
        }catch(Exception e){System.out.println(e);}
        return i;
    }
}

LoginActionBean.java

package login.Action;

import DbCon.DataConnection;
import com.opensymphony.xwork2.ActionSupport;
import java.sql.ResultSet;
import java.sql.SQLException;

public class LoginActionBean extends ActionSupport {
public String uname,pass;

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    public String getUname() {
        return uname;
    }

    public void setUname(String uname) {
        this.uname = uname;
    }

    public String execute() throws SQLException
    {
        DataConnection db=new DataConnection();
        ResultSet rs=db.exeQuery("select * from admin where name='"+uname+"' and  pass='"+pass+"'");
        if(rs.next())
         return SUCCESS;
        else
        return ERROR;
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:42:47+00:00Added an answer on June 10, 2026 at 10:42 am

    Well you have already done most of the work, so you can do some simple things like in you action class

    1. Create a bean say TeamDetails with properties you want to show in JSP
    2. define this bean in your Action class and fill it using DB call
    3. use OGN in your JSP to access data and show it using struts2 tag.

    Action class:

    public class TeamDetailAction extends ActionSupport{
      List<TeamDetailData> teamDetails;
       //getter and setter
    
     public String execute() throws Exception{
                 teamDetails=fill it by retrieving from BD
        }
    }
    

    TeamDetailData Java

    public class TeamDetailData{
    
     private teamMemberName;
     // other properties
    //getter and setters
    }
    

    on your JSP using OGNL iterator tag to show the data

    JSP page

    <s:iterator value="teamDetails">
      <p>Name : <s:property value="teamMemberName"/></p>
    </s:iterator>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.