7 Replies - 1103 Views - Last Post: 26 October 2013 - 06:59 PM

#1 Dankwansere  Icon User is offline

  • D.I.C Regular

Reputation: 82
  • View blog
  • Posts: 255
  • Joined: 09-November 09

Trying to execute my gui java application in JSP

Posted 26 October 2013 - 08:19 AM

Hey guys, So I did a University enrollment project before in java, and I just recently broke it down into MVC architecture. The program works well and everything. But now i'm trying to learn J2EE, so far I know my basics. So this is what i'm trying to do. I have basic html login page. that login page calls my servlet and my servlet will call the JSP. i'm trying to execute my univeristy gui app in the JSP but its not running(Well the GUI part is not showing). Here's my code is a bit alot..


Student class

package com.example.model;
/**
 *  Name: Eric Sarpong      
 *  Student #: 210 532 232
 */


public class Student
{
	
	private String name, uni1, uni2, uni3;
	private boolean accept1, accept2, accept3;
	private double average;
	
	public Student()
	{
		this.name = null;
		this.uni1 = null;
		this.uni2 = null;
		this.uni3 = null;
				
	}
	
	public Student(String name, String uni1, String uni2, String uni3, double average)
	{
		this.name = name;
		this.uni1 = uni1;
		this.uni2 = uni2;
		this.uni3 = uni3;
		this.average = average;
	}
	
	public String getName()
	{
		return this.name;
	}
	
	public String getUni1()
	{
		return this.uni1;
	}
	public String getUni2()
	{
		return this.uni2;
	}
	public String getUni3()
	{
		return this.uni3;
	}
	public double getAverage()
	{
		return this.average;
	}
	
	public void setAcceptance(int num, boolean decision)
	{
	
		if(num == 1)
		{
			this.accept1 = decision;
		}
		else if(num == 2)
		{
			this.accept2 = decision;
		}
		else if(num == 3)
		{
			this.accept3 = decision;
		}
	}
	public String toString()
	{
		String[] result = new String[3];
		
		if(this.accept1 == true)
		{
			result[0] = "Accepted";
		}
		else
		{
			result[0] = "Rejected";
		}
		
		if(this.accept2 == true)
		{
			result[1] = "Accepted";
		}
		else
		{
			result[1] = "Rejected";
		}
		if(this.accept3 == true)
		{
			result[2] = "Accepted";
		}
		else
		{
			result[2] = "Rejected";
		}
		
		return this.name +":" + "\t\n" + "GPA: " + "\t\t" + this.average + "\n" + this.getUni1() + ":" + "\t\t" + result[0] +
				"\n" + this.getUni2() + ":" + "\t\t" + result[1] + 
				"\n" + this.getUni3() + ": \t\t"  + result[2] + "\n";
	}
}




Model class Uni enrolllment
package com.example.model;


public class UniModel 
{
	private Student S1[];
	String name, uni1, uni2, uni3;
	double average;
	
	private static int count = 0; //This "count" variable will be used as the index for the array of Student Object
	
	public UniModel()
	{
		this.S1 = new Student[100]; 
	} 
	
	public void addStudent(String name, String uni1, String uni2, String uni3, double average)
	{
		this.name = name;
		this.uni1 = uni1;
		this.uni2 = uni2;
		this.uni3 = uni3;
		this.average = average;
	
		this.S1[count] = new Student(this.name, this.uni1, this.uni2, this.uni3, this.average);
		this.count++;
	}
	
	public String  searchStudent(String searchName)
	{
		/*
		 * this method will search for the student that is entered in the text field
		 */
		String tempName = searchName; //Getting the name that the user inputed
		String result = null;
		
		for(int i = 0; i < count; i++)
		{
			if(S1[i].getName().equals(tempName))
			{
				result = (S1[i].toString());
				break;
			}		
		}
		return result;	
	}
	
	public int getCount()
	{
		return this.count;
	}
		
	public void decision(String name, boolean uni1, boolean uni2, boolean uni3)
	{
		int tempNum = 0;
		
		for(int i = 0; i < count; i++)
		{
			if(S1[i].getName().equals(name))
			{
				tempNum = i;
				break;
			}
			
		}
		
		S1[tempNum].setAcceptance(1, uni1);
		S1[tempNum].setAcceptance(2, uni2);
		S1[tempNum].setAcceptance(3, uni3);
		
	}
	
	public String getUni1(int index)
	{
		return S1[index].getUni1();
	}
	
	public String getUni2(int index)
	{
		return S1[index].getUni2();
	}
	
	public String getUni3(int index)
	{
		return S1[index].getUni3();
	}
	
	public void setAcceptance(int index, boolean result1, boolean result2, boolean result3)
	{
		S1[index].setAcceptance(1, result1);
		S1[index].setAcceptance(2, result2);
		S1[index].setAcceptance(3, result3);
		
	}
	
	public String[] listAllStudent()
	{
		Student temp = new Student();
		for(int i = 0; i < count; i++)
		{
			for(int c = 0; c < count - 1; c++)
			{
				if(this.S1[c].getAverage() > this.S1[c + 1].getAverage())
				{
					temp = this.S1[c];
					this.S1[c] = this.S1[c + 1];
					this.S1[c + 1] = temp;
				}
			}
		}
		
		String tempList[] = new String[count];
		for(int i = 0; i < count; i++)
		{
			
			tempList[i] = S1[i].toString();
		}
		
		return tempList;
		
	}
	
	public String toString(int index)
	{
		return S1[index].toString();
	}
	
	
	
	
		
}




University Controller
import com.example.model.*; 
import com.example.view.*;
import java.awt.*;
import java.awt.event.*;

public class UniController extends UniModel
{
	 private UniModel model;
	  UniView  view;
	 private ActionListener actionListener;
	 private ActionListener actionListener2;
	 
	 public UniController(UniModel model, UniView view)
	 {
		 this.model = model;
		 this.view = view;
	 }
	 
	 

	 
	 public void addStudentControl() {
		 actionListener = new ActionListener() {
			 public void actionPerformed(ActionEvent AE) {
			 	addStudent();
		 	}
		 };
		 this.view.getSubmitButton().addActionListener(actionListener);
	 }
	 
	 public void admitStudentControl() {
		 	actionListener2 = new ActionListener() {
		 		public void actionPerformed(ActionEvent AE) {
		 			admitStudent();
		 		}
		 	};
		 	
		 	this.view.getComboList().addActionListener(actionListener2);
	 }
	 
	 public void displayAllControl() 
	 {
		 actionListener = new ActionListener() {
			 public void actionPerformed(ActionEvent AE) {
			 	displayAllStudent();
		 	}
		 };
		
		this.view.getDisplayAllButton().addActionListener(actionListener);
	 }
	
	
	 
	 public void acceptStudentControl() {
		 actionListener = new ActionListener() {
			 public void actionPerformed(ActionEvent AE) {
			 	selectAcceptance();
		 	}
		 };
		this.view.getSubmitButton2().addActionListener(actionListener);
	 }
	 
	 public void displayOneStudent() {
		 actionListener = new ActionListener() {
			 public void actionPerformed(ActionEvent AE) {
			 	searchOneStudent();
		 	}
		 };
		this.view.getTextField3().addActionListener(actionListener);
		this.view.getEnterButton().addActionListener(actionListener);
		
	 }

	 /*-------------------------------------------------------------------------*/

	 
	 private void displayAllStudent()
	 {
		 String[] listOfStudentsArray = new String[this.model.getCount()];
		 listOfStudentsArray = this.model.listAllStudent();
		 
		 for(int i = 0; i < listOfStudentsArray.length; i++)
		 {
			
			this.view.getTextArea1().append(listOfStudentsArray[i] + "\n");
		 }
		 
		 
		 
		
	 }
	 
	 
	 private void searchOneStudent()
	 {
		 System.out.println(this.view.getTextArea1().getText());
		 String nameOfStudent = this.view.getTextField3().getText();
		 String result = null;
		 
		 result = this.model.searchStudent(nameOfStudent);
		 
		 this.view.getTextArea2().setText(result);
		 
		 
	 }
	 	
	 
	 private void selectAcceptance()
	 {
		 boolean result1;
		 boolean result2;
		 boolean result3;
		 int index = this.view.getIndextOfNameSelected();
		 result1 = this.view.isButton1Selected();
		 result2 = this.view.isButton2Selected();
		 result3 = this.view.isButton3Selected();
		 this.model.setAcceptance(index, result1, result2, result3);
		  
	 }
	 
	 private void addStudent()
	 {
		 String tempName = null;
		 Double tempAverage = 0.0;
		 
		 Object[] indexes = new Object[2];
		 indexes = view.getUniIndexes();
		 
		 String uni1 = (String) indexes[0];
		 String uni2 = (String) indexes[1];
		 String uni3 = (String) indexes[2];
		 
		 
		 tempName = this.view.getStudentName();
		 tempAverage = this.view.getStudentAverage();
		 
		 this.model.addStudent(tempName, uni1, uni2, uni3, tempAverage);
		 this.view.getComboList().addItem(tempName);
		 
		// System.out.println(this.view.getComboList().getItemCount());
		
		 this.view.setStudentCount(this.model.getCount());	//Incrementing the count on gui
		 
		 
				 
	 }
	 
	 private void admitStudent()
	 {
		 int index = 0;
		 String uni1;
		 String uni2;
		 String uni3;
		 
		 index = this.view.getComboList().getSelectedIndex();
		 uni1 = this.model.getUni1(index);
		 uni2 = this.model.getUni2(index);
		 uni3 = this.model.getUni3(index);
		 
		 this.view.setUniLabel(uni1, uni2, uni3);
		 
		 
	 }
}




University view

package com.example.view;
/**
 * 
 * Nam: Eric Sarpong
 * 
 * 
 **/

import javax.swing.*;  


import java.awt.*;
import java.awt.event.*;

import javax.swing.border.*;

public class UniView   {

	private CardLayout C1 = new CardLayout(20, 10);
	private JPanel cardPanel = new JPanel(C1); //This is the panel that will hold the card layout
	private JPanel mainPanel = new JPanel(new BorderLayout(1,1)); //This is the main panel that will hold everything
	private JPanel rightPanel = new JPanel();
	private JPanel leftPanel = new JPanel(new FlowLayout()); // This panel will be the left sub panel of the main panel
	private JPanel leftGrid = new JPanel(new GridLayout(4,1, 0, 40)); //This grid panel will hold the 4 main buttons
	
	private int count = 0;
	
	private JPanel admitSubPanel = new JPanel(new GridLayout(4,3));
	
	/* 
	 * These sub panels will be used to layout the extra contents that will
	 * be displayed in the right panel of the main panel
	 * */
	private JPanel subRightPanel2 = new JPanel(new BorderLayout());
	private JPanel SubRightPanel3 = new JPanel(new GridLayout(1,1));
	private JPanel subRightPanel4 = new JPanel(new BorderLayout());
	private JPanel miniPanel4 = new JPanel(new GridLayout(1,1));
	private JPanel miniPanel = new JPanel();
	
	//Creating the buttons 
	private JButton input, admit, displayAll, displayOne, submit, submit2, enter;
	
	
	//Creating a string array to hold the list of universities
	private String[] uniNames = {"University of Toronto", "York University", "Western University", 
				"Brock University", "Guelph University", "University of Waterloo", "McGill University", "Concordia University",
				"Laval University", "McMaster University"};
		
	//JList component to contain a list of the 10 Canadian Universities
	private JList uniList; 
	
	//Creating Labels
	private JLabel Label1, Label2, studentCount, uniLabel1, uniLabel2, uniLabel3, finalLabel, prompt;
	//Creating TextFields
	private JTextField textOne, textTwo, textThree;
	//Creating a ComboBox
	private JComboBox comboChoiceList;
	
	private int index; //This "index" variable will be used as the index for the comboChoiceList
	
	private double average; //This variable will hold the student's grade value
	
	
	//Creating the university radio buttons
	private JRadioButton uni1Accepted, uni1Rejected, uni2Accepted, uni2Rejected, uni3Accepted, uni3Rejected; //turn these into an array
	
	
	//Creating 3 button groups that will hold each of the university radio buttons
	private ButtonGroup group1 = new ButtonGroup();
	private ButtonGroup group2 = new ButtonGroup();
	private ButtonGroup group3 = new ButtonGroup();
	
	/*
	 * These two textArea components will be used for the "Display All" and "Display One" panel. 
	 * They will be used to list the Student(s) info.
	 */
	private JTextArea textArea = new JTextArea();
	private JTextArea textArea2 = new JTextArea();
	
	private String[] currentStudentNames = new String[0];
	
	//
	//private UniModel U1 = new UniModel();
	
	
	
	
	@SuppressWarnings("deprecation")
	public UniView()
	{
		//Initializing the button labels
		this.input = new JButton("Input");
		this.admit = new JButton("Admit");
		this.displayAll = new JButton("Display All");	
		this.displayOne = new JButton("Display One");
		this.submit2 = new JButton("submit");
		
		// setting University labels
		this.uniLabel1 = new JLabel("");
		this.finalLabel = new JLabel("");
		
		//Creating Radio Buttons for the universities that were chosen for a specific student
		this.uni1Accepted = new JRadioButton("Accepted", false);
		this.uni1Rejected = new JRadioButton("Rejected", true);
		//Adding the university radio buttons to a group
		group1.add(this.uni1Accepted);
		group1.add(this.uni1Rejected);
		
		this.uniLabel2 = new JLabel("");
		this.uni2Accepted = new JRadioButton("Accepted", false);
		this.uni2Rejected = new JRadioButton("Rejected", true);
		group2.add(this.uni2Accepted);
		group2.add(this.uni2Rejected);
		
		this.uniLabel3 = new JLabel("");
		this.uni3Accepted = new JRadioButton("Accepted", false);
		this.uni3Rejected = new JRadioButton("Rejected", true);
		group3.add(this.uni3Accepted);
		group3.add(this.uni3Rejected);
		
		
		//adding the buttons to the leftPanel components
		this.leftGrid.add(this.input);
		this.leftGrid.add(this.admit);
		this.leftGrid.add(this.displayAll);
		this.leftGrid.add(this.displayOne);
		
	
		
		
		this.leftPanel.add(this.leftGrid); //To hold the Left Grid panel components
		
		/*
		 * Setting more of the panels to a specific line border color
		 */
		this.leftGrid.setBorder(new LineBorder(Color.GRAY));
		this.leftPanel.setBackground(Color.LIGHT_GRAY);
		this.leftPanel.setBorder(new LineBorder(Color.BLACK));
		this.leftPanel.setBackground(Color.DARK_GRAY);
		this.mainPanel.add(this.leftPanel, BorderLayout.WEST); //Placing the left panel to the west of the Main Panel
		this.cardPanel.setBorder(new LineBorder(Color.BLACK));	
		this.mainPanel.setBackground(Color.GRAY);
		
		/*
		 * Calling all the methods of the cardlayout panels
		 */
		//-----------------------------1st Card Layout (Input Panel)-------------------------------------//
		this.inputPanel();
		//-----------------------------2nd Card Layout (Admit Panel)-------------------------------------//
		this.admitPanel();
		//-----------------------------3rd Card Layout (Display All Panel)-------------------------------//
		this.displayAllPanel();
		//-----------------------------4th Card Layout (Display one Panel)-------------------------------//
		this.displayOne();
		
		//Adding listeners to the buttons, combo choice list and JtextField 
		this.input.addActionListener(new leftPanelButtons());
		this.admit.addActionListener(new leftPanelButtons());
		this.displayAll.addActionListener(new leftPanelButtons());
		this.displayOne.addActionListener(new leftPanelButtons());
		
		
		//add(this.mainPanel);
		//resize(700,500); 
		JFrame frame = new JFrame("gege");
		
		frame.add(this.mainPanel);
		
		frame.setVisible(true);
		frame.setSize(700, 500);
		
		
	}
	
	private void inputPanel()
	{
		/*
		 * Initializing the Labels, Text fields and Buttons
		 */
		this.prompt = new JLabel("Choose exactly 3 universities: Use CTRL or SHIFT ");
		this.Label1 = new JLabel("Enter Student Name");
		this.Label2 = new JLabel("Enter Student Average");
		this.textOne = new JTextField("", 8);
		this.textTwo = new JTextField("", 8);
		this.uniList = new JList(uniNames);
		this.submit = new JButton("Submit");
		this.studentCount = new JLabel("student " + this.count + " out of 100 ");
		
		this.uniList.setBorder(new LineBorder(Color.BLACK)); //setting the uniList border black
		
		
		JPanel subRightPanel1 = new JPanel(new GridLayout(2,2)); //Creating a separate panel to hold the 2 labels and text fields
		JPanel bottomPanel = new JPanel(new GridLayout(2,1, 10,10));
	
		
		subRightPanel1.add(this.submit);
		subRightPanel1.add(this.Label1);
		subRightPanel1.add(this.textOne);
		subRightPanel1.add(this.Label2);
		subRightPanel1.add(this.textTwo);
		
		
		bottomPanel.add(this.submit);
		bottomPanel.add(this.prompt);
		/*
		 *Creating a Border Layout panel to hold subRightPanel1 which holds the 2 labels and text fields
		 *and this panel will also hold the UniList component along with a submit button 
		 */
		JPanel b1 = new JPanel(new BorderLayout()); 
		b1.add(subRightPanel1, BorderLayout.NORTH);
		b1.add( new JScrollPane(this.uniList), BorderLayout.CENTER);
		b1.add(bottomPanel, BorderLayout.SOUTH);
		
		/*
		 * Adding the b1 panel to the main right panel, along with the student counter label
		 */
		this.rightPanel.add(b1);
		this.rightPanel.add(this.studentCount); //Adding the student counter to the right panel
		
		this.cardPanel.add(this.rightPanel, String.valueOf(1)); //Adding the right Panel to the card panel
		this.mainPanel.add(this.cardPanel, BorderLayout.EAST); //Adding the card panel to the main panel
	}
	
	public void admitPanel()
	{
		/*
		 * When this method is called it will layout all the components
		 * necessary for the admit panel
		 */
		
		//Initializing the comboChoiceList
		this.comboChoiceList = new JComboBox(this.currentStudentNames);
		this.comboChoiceList.setBorder(new LineBorder(Color.BLACK));
		
		
		this.subRightPanel2.add(comboChoiceList, BorderLayout.NORTH); //Adding the combochoiceList to the subRightPanel2
		/*
		 * Setting the uniLabels visibility to false
		 */
		this.uniLabel1.setVisible(false);
		this.uniLabel2.setVisible(false);
		this.uniLabel3.setVisible(false);
		
		//Setting the radio buttons visible
		this.uni1Accepted.setVisible(false);
		this.uni1Rejected.setVisible(false);
		
		this.uni2Accepted.setVisible(false);
		this.uni2Rejected.setVisible(false);
		
		this.uni3Accepted.setVisible(false);
		this.uni3Rejected.setVisible(false);
		
		this.submit2.setVisible(false);
				
		//Adding the labels and radio buttons to the admitSubPanel
		this.admitSubPanel.add(this.uniLabel1);
		this.admitSubPanel.add(this.uni1Accepted);
		this.admitSubPanel.add(this.uni1Rejected);
		
		this.admitSubPanel.add(this.uniLabel2);
		this.admitSubPanel.add(this.uni2Accepted);
		this.admitSubPanel.add(this.uni2Rejected);
	
		this.admitSubPanel.add(this.uniLabel3);
		this.admitSubPanel.add(this.uni3Accepted);
		this.admitSubPanel.add(this.uni3Rejected);
		this.miniPanel.add(this.submit2);
		this.admitSubPanel.add(this.miniPanel);
		
		this.subRightPanel2.add(this.admitSubPanel, BorderLayout.CENTER);
		this.subRightPanel2.setBorder(new LineBorder(Color.BLACK));
		
		this.cardPanel.add(this.subRightPanel2, String.valueOf(2));
		this.mainPanel.add(this.cardPanel, BorderLayout.EAST);
	}
	
	public void displayAllPanel()
	{
		/* When this method is called it will display all of the students and averages in descending order
		 */
		this.textArea.setFont(new Font("Serif", Font.ITALIC, 12)); //Setting the font style of the JtextArea to Serif
		
		this.SubRightPanel3.add(new JScrollPane(this.textArea)); //Adding the JtextArea component to the SubRightPanel3
		this.cardPanel.add(this.SubRightPanel3, String.valueOf(3)); //Adding the SubRightPanel3 to the Card Panel
		
		this.mainPanel.add(this.cardPanel, BorderLayout.EAST); //Adding the card Panel to the Main panel
	}
	public void displayOne()
	{
		/*
		 * When this method is called, it will allow the user to enter a name and display the name and average in the text area
		 */
		this.textThree = new JTextField("", 8);
		this.enter = new JButton("Enter");
		this.textThree.setBorder(new LineBorder(Color.BLACK));
		this.textArea2.setFont(new Font("Arial", Font.PLAIN, 14)); //setting the font of the text area to Arial, size 14
		
		this.finalLabel.setText("Enter student name: ");
		
		this.miniPanel4.add(this.finalLabel);
		this.miniPanel4.add(this.textThree);
		this.miniPanel4.add(this.enter);
		
		this.miniPanel4.setBorder(new LineBorder(Color.BLACK));
		
		this.subRightPanel4.add(this.miniPanel4, BorderLayout.NORTH);
		this.subRightPanel4.add(new JScrollPane(this.textArea2), BorderLayout.CENTER);
		
		this.cardPanel.add(this.subRightPanel4, String.valueOf(4));
		this.mainPanel.add(this.cardPanel, BorderLayout.EAST);
	}
	
	private class leftPanelButtons implements ActionListener
	{
		public void actionPerformed(ActionEvent event)
		{
			/*
			 * Depending on which button the user clicks, the following codes will be initiated
			 */
			if(event.getSource() == admit)
			{		
				C1.show(cardPanel, "2");
				textArea2.setText("");
				
			}
			
			else if(event.getSource() == input)
			{
				
				C1.show(cardPanel, "1");
				//textArea.setText("");
				textArea2.setText("");
				
			}
			else if(event.getSource() == displayAll)
			{
				
				C1.show(cardPanel, "3");
				textArea2.setText("");
				textArea.setBorder(new LineBorder(Color.BLACK));
				
			}
			else if(event.getSource() == displayOne)
			{
				C1.show(cardPanel, "4");
				textArea.setText("");
				textArea2.setBorder(new LineBorder(Color.BLACK));
				
			}	
		}
	}
	
	public JButton getSubmitButton()
	{
		return this.submit;
	}
	
	public JButton getEnterButton()
	{
		return this.enter;
	}
	
	public JButton getDisplayOneButton()
	{
		return this.displayOne;
	}
	
	public JTextField getTextField3()
	{
		return this.textThree;
	}
	
	public JTextArea getTextArea1()
	{
		
		return this.textArea;
	}
	
	public JTextArea getTextArea2()
	{
		return this.textArea2;
	}
	
	public JButton getDisplayAllButton()
	{
		return this.displayAll;
	}
	
	public JButton getSubmitButton2()
	{
		return this.submit2;
	}
	
	public JComboBox getComboList()
	{
		return this.comboChoiceList;
	}
	
	public int getIndextOfNameSelected()
	{
		return this.comboChoiceList.getSelectedIndex();
	}
	
	public String getStudentName()
	{
		return this.textOne.getText();
	}
	
	public Double getStudentAverage()
	{
		return Double.parseDouble(this.textTwo.getText());
	}
	
	public Object[] getUniIndexes()
	{
		return this.uniList.getSelectedValues();
	}
	
	public void setStudentCount(int count)
	{
		 this.count = count;
		 this.studentCount.setText("student " + this.count + " out of 100");
	}
	
	public void setUniLabel(String uni1, String uni2, String uni3 )
	{
		
		/* This method will set the the corresponding radio buttons along with its labels visibility to true.
		 * It will get the corresponding universities from the student object
		 */
		  
		this.uniLabel1.setText(uni1);
		this.uniLabel2.setText(uni2);
		this.uniLabel3.setText(uni3);
		
		
		//Setting university labels visible
		this.uniLabel1.setVisible(true);
		this.uniLabel2.setVisible(true);
		this.uniLabel3.setVisible(true);
		
		//Setting the radio buttons visible
		this.uni1Accepted.setVisible(true);
		this.uni1Rejected.setVisible(true);
		
		this.uni2Accepted.setVisible(true);
		this.uni2Rejected.setVisible(true);
		
		this.uni3Accepted.setVisible(true);
		this.uni3Rejected.setVisible(true);
		
		this.submit2.setVisible(true);
	} 
	
	public boolean isButton1Selected()
	{
		boolean temp = false;
		if(this.uni1Accepted.isSelected())
		{
			temp = true;
		}
		return temp;
	}
	public boolean isButton2Selected()
	{
		boolean temp = false;
		if(this.uni2Accepted.isSelected())
		{
			temp = true;
		}
		return temp;
	}
	
	public boolean isButton3Selected()
	{
		boolean temp = false;
		if(this.uni3Accepted.isSelected())
		{
			temp = true;
		}
		return temp;
	}
	
	public ButtonGroup getButton3()
	{
		return this.group3;
	}

}




-----------------------------------------

This part will be the HTML login, servlet and JSP

login page

<font face="verdana,arial" size=-1>
<center><table cellpadding='2' cellspacing='0' border='0' id='ap_table'>
<tr><td bgcolor="blue"><table cellpadding='0' cellspacing='0' border='0' width='100%'><tr><td bgcolor="blue" align=center style="padding:2;padding-bottom:4"><b><font size=-1 color="white" face="verdana,arial"><b>Enter your login and password</b></font></th></tr>
<tr><td bgcolor="white" style="padding:5"><br>
<form method="post" action="UniEnroll.do" name="aform" target="_top">
<!-- <input type="hidden" name="action" value="login"> 
<input type="hidden" name="hide" value=""> -->
<center><table>
<tr><td><font face="verdana,arial" size=-1>Login:</font></td><td><input type="text" name="login"></td></tr>
<tr><td><font face="verdana,arial" size=-1>Password:</font></td><td><input type="password" name="password"></td></tr>
<tr><td><font face="verdana,arial" size=-1>&nbsp;</font></td><td><font face="verdana,arial" size=-1><input type="submit" value="Send"></font></td></tr>
<tr><td colspan=2><font face="verdana,arial" size=-1>&nbsp;</font></td></tr>
<tr><td colspan=2><font face="verdana,arial" size=-1>Lost your username or password? Find it <a href="http://www.authpro.com/auth/orthodoxrings/?action=lost">here</a>!</font></td></tr>
<tr><td colspan=2><font face="verdana,arial" size=-1>Not member yet? Click <a href="http://www.authpro.com/auth/orthodoxrings/?action=reg">here</a> to register.</font></td></tr>
</table></center>
</form>
</td></tr></table></td></tr></table>




Uni servlet

package com.example;
import java.io.IOException;
import java.io.PrintWriter;

import com.example.*;
import com.example.model.UniModel;

import javax.servlet.*;
import javax.servlet.http.*;

public class UniServlet extends HttpServlet {
	
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {
		
		
		
		response.setContentType("text/html");
		
		PrintWriter out = response.getWriter();
		
		out.println("Beer Selection Advice <br>");
		
		String name = request.getParameter("login");
		String password = request.getParameter("password");
		
		out.println("<br> name is: " + name);
		
		if(name.equals("Eric"))
		{
			
			RequestDispatcher view =
					request.getRequestDispatcher("result.jsp");
		
		view.forward(request, response); 
			
			}
	
		}
	}



JSP

<html>
<body>
<h1 align="center">JSP Test </h1>
<p>

<%
	
	out.println("Result JSP check");
	
	main m1 = new main();
	m1.show();
	
	
	out.println("<br> your number is from MAIN 2 class is : " + m1.getNum());
		
	
%>

</body>
</html>



I did some little test to see if the main class was working in the JSP and it was. i did a little get method that just returns a int as a test. and that method works but i'm wondering
how come the m1.show() method does not work? Do I have to convert my uni enrollment program to an applet before it works on jsp?

This post has been edited by Dankwansere: 26 October 2013 - 08:20 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Trying to execute my gui java application in JSP

#2 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1159
  • View blog
  • Posts: 2,547
  • Joined: 05-May 05

Re: Trying to execute my gui java application in JSP

Posted 26 October 2013 - 08:24 AM

<form method="post" action="UniEnroll.do" name="aform" target="_top">



You should be referencing the actual servlet name in the form action -- UniServlet. Also make sure you look at the server console for any errors. If none are being produced upon the request to the servlet, then it's not getting called at all, and it's probably because of the aforementioned issue.
Was This Post Helpful? 0
  • +
  • -

#3 Dankwansere  Icon User is offline

  • D.I.C Regular

Reputation: 82
  • View blog
  • Posts: 255
  • Joined: 09-November 09

Re: Trying to execute my gui java application in JSP

Posted 26 October 2013 - 08:44 AM

The servlet and everything works fine without any error. I put UniEnroll.do because that's how I mapped it in my web.xml file.

My problem is that the JSP runs fine but it does not run the method that I have in there which is m1.show();

that method should show my uni gui application.
Was This Post Helpful? 0
  • +
  • -

#4 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1159
  • View blog
  • Posts: 2,547
  • Joined: 05-May 05

Re: Trying to execute my gui java application in JSP

Posted 26 October 2013 - 09:59 AM

I'm sorry I missed the part about main in your first post. Well, where is main?? It's not posted. Without even seeing it, how do you expect to write to the server's output stream without sending it to main?

This post has been edited by blackcompe: 26 October 2013 - 10:00 AM

Was This Post Helpful? 0
  • +
  • -

#5 Dankwansere  Icon User is offline

  • D.I.C Regular

Reputation: 82
  • View blog
  • Posts: 255
  • Joined: 09-November 09

Re: Trying to execute my gui java application in JSP

Posted 26 October 2013 - 12:14 PM

I forgot to post the main, here it is;

Main

package com.example.main;

import com.example.controller.*; 
import com.example.view.*;
import com.example.model.*;

public class main 
{

	UniModel model = new UniModel();
	UniView view = new UniView();
	UniController controller;
	
	public main()
	{
		this.controller = new UniController(this.model, this.view);
		
		
	}
	
	public int getNum()
	{
		return 777;
	}
	
	public void show()
	{
		controller.addStudentControl();
		controller.admitStudentControl();
		controller.acceptStudentControl();
		controller.displayAllControl();
		
		System.out.println("Main is running");
		
	}
	
	
}




the getNum method was just to test if this main class was working and if the jsp could call it. how come the jsp can call the getNum() method but it does'nt call the show() method
Was This Post Helpful? 0
  • +
  • -

#6 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1159
  • View blog
  • Posts: 2,547
  • Joined: 05-May 05

Re: Trying to execute my gui java application in JSP

Posted 26 October 2013 - 02:11 PM

Quote

m1.show() method does not work


My questions still stands. You can't output any HTML in the servlet response without access to the response's output stream. Perhaps something like the following would show whatever the output of your MVC code is.

m1.show(out);

class Main { void show(PrintWriter pw) { out.println("Coming from Main class"); } }



Please see the API for HttpServletResponse, and also read the Java EE tutorials. If you're just learning, then why not go through the tons of tutorials that exist or pick up a good book on the subject?

This post has been edited by blackcompe: 26 October 2013 - 02:15 PM

Was This Post Helpful? 0
  • +
  • -

#7 Dankwansere  Icon User is offline

  • D.I.C Regular

Reputation: 82
  • View blog
  • Posts: 255
  • Joined: 09-November 09

Re: Trying to execute my gui java application in JSP

Posted 26 October 2013 - 05:19 PM

Okay thanks will do. quick question tho. Learning J2EE do you recommend anything I should focus more while learning J2EE, servlets and JSP? because I'm reading the "Oreily Head first servlets and JSP" and there's so much information to grasp
Was This Post Helpful? 0
  • +
  • -

#8 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1159
  • View blog
  • Posts: 2,547
  • Joined: 05-May 05

Re: Trying to execute my gui java application in JSP

Posted 26 October 2013 - 06:59 PM

JSP allows you to intertwine Java in markup, like PHP. It's more view oriented IMO. Servlets are more back-endish. Use them together. Put your view in JSP and logic in a servlet.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1