martin5211 37 Posting Whiz in Training

It seems to be a permission issue with profile folder. Grant access to everyone on these folders temporarily.

martin5211 37 Posting Whiz in Training

Post this issue on Web Design/HTML and CSS forum. I think div align="center" is deprecated. margin:0 auto; before margin-top should work.

martin5211 37 Posting Whiz in Training

Ok, you can use sessions. Before redirection, use session.setAttribute("logout", true) . Then, into the login page you can place if(session.getAttribute( "logout" ).equals(true)){ ... } with the invalidation session code.

martin5211 37 Posting Whiz in Training

Have you tried if(saw == "") ?

martin5211 37 Posting Whiz in Training

The code performs a redirection after log out?

martin5211 37 Posting Whiz in Training

Are you using JSP or a Servlet to logout?

martin5211 37 Posting Whiz in Training

There is a class named Apache Commons Lang that provides a method to check is String:

API documentation

Download

martin5211 37 Posting Whiz in Training

Create a JAR file, it is executable in almost all brand new computers with Java Runtime Environment installed.

martin5211 37 Posting Whiz in Training

What data type is associated with name and city?

martin5211 37 Posting Whiz in Training

Is it a PS3 file?

martin5211 37 Posting Whiz in Training

It's viable to use several panels (could be three) and use e.g. setLocation(130,10) to change the position of the panels. Setting a different background with setBackground(Color.white) and setSize(width,height) could help too in the positioning.

martin5211 37 Posting Whiz in Training

Remove the static modifiers in your Book class. Also you need to pass a new Book object on each iteration, e.g. mybooks.add(new Book(a_title, a_author,a_publisher, a_isbn)); if you have a constructor to initialize these variables.

martin5211 37 Posting Whiz in Training

Try with getResourceAsStream(). I think that class can access inside JAR files.

martin5211 37 Posting Whiz in Training

In editData.jsp the textboxes appears before calling request.getParameter() for each variable. For that reason every textbox is empty. Try to move the block of get parameters above, next to variable declarations.

martin5211 37 Posting Whiz in Training

Have you tried to do drag&drop these files into src/ of the Project Explorer (Eclipse) and then select "copy"?

martin5211 37 Posting Whiz in Training

It is not possible, the kind of action of the link is to redirect to another page.

martin5211 37 Posting Whiz in Training

I found some errors in your code:

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
		The Main class creates the GUI for the Dorm and 
		Meal charges.
 */
public class Main extends JFrame
{
	private JPanel dormPanel;
	private JComboBox dormBox;
	private JPanel mealPanel;
	private JComboBox mealBox;
	private JPanel totalChargesPanel;
	private JPanel selectedMealPanel;
	private JPanel buttonPanel;
	private JButton calcButton;
	private JLabel label1;
	private JTextField totalCharges;

	private String[] dorm = { "Allen Hall: $1,500 per semester", 
			"Pike Hall: $1,600 per semester", 
			"Farthing Hall: $1,200 per semester", 
	"University Suites: $1,800 per semester"};

	private String[] meal = { "7 meals per week: $650 per semester", 
			"14 meals per week: $1,095 per semester", 
	"Unlimited meals: $1,500 per semester"};

	/**
   		Constructor
	 */
	public Main()
	{
		super("Dormitory and Meal Plan");

		// Specify an action for the close button.
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		// Create a BorderLayout manager.
		setLayout(new BorderLayout());

		// Create the dorm and meal panel.      
		buildDormPanel();
		buildMealPanel();
		buildSelectedTotalChargesPanel();
		buildButtonPanel();

		// Add the components to the content pane.   
		add(dormPanel, BorderLayout.WEST);
		add(mealPanel, BorderLayout.EAST);
		add(totalChargesPanel, BorderLayout.SOUTH);
		add(buttonPanel, BorderLayout.NORTH);

		// Pack the contents of the window and display it.    
		pack();
		setVisible(true);
	}

	// The buildDormPanel method builds the dorm panel.	
	private void buildDormPanel()
	{
		// Create the dorm panel.      
		dormPanel = new JPanel();
		dormBox = new JComboBox(dorm);

		// Register the action listener.      
		dormBox.addActionListener(new ComboBoxListener());

		// Add the dorm panel to the panel.
		dormPanel.add(dormBox);
	}

	// The buildMealPanel method builds the meal panel.	
	private void buildMealPanel()
	{
		// Create the meal panel. …
martin5211 37 Posting Whiz in Training

On the land page (JSP) when a user performs logout.

e.g. if the user goes to home, would be nice to get an attribute and put the destroy code inside a condition.

So, first use request.setAttribute on the logout servlet to set a property to the land page.

Then, get that property from the land page and if that property isn't null execute the destroy code.

martin5211 37 Posting Whiz in Training

I'm thinking a better method:

HttpSession s = request.getSession(false); 
s.invalidate();

Destroying the session directly.

martin5211 37 Posting Whiz in Training

Create a new method in SessionCounter, let's say discount():

public static void discount() {
		if(activeSessions > 0)
			activeSessions--;
	}

Then, call discount() from wherever you do logout, preferable from the servlet:

import com.stardeveloper.web.listener.SessionCounter;

. . .

SessionCounter.discount();
martin5211 37 Posting Whiz in Training

If the method sessionDestroyed() is declared static it's possible to access it from the logout method using SessionCounter.sessionDestroyed() .

martin5211 37 Posting Whiz in Training

Post the issue in a separate thread. Post the code and we'll try to fix it.

martin5211 37 Posting Whiz in Training

This can be solved using a trim function from client-side, Javascript.

martin5211 37 Posting Whiz in Training

Maybe, I'm using different application server and browser. Use trim() to remove leading/trailing spaces in ContactServlet:

request.setAttribute("emailState", email.trim());
martin5211 37 Posting Whiz in Training

I can't reproduce the error. Any other hint you could give me?

martin5211 37 Posting Whiz in Training

Go to the folder $JBOSS_HOME/server/default/conf/ and open jboss-service.xml into an editor. Where it says "org.jboss.web.WebService" go to the attribute Port. Delete the line "<value-factory bean="ServiceBindingManager" method="getIntBinding" parameter="jboss:service=WebService"/>" and put instead 8085, leaving in this way the line as:

<mbean code="org.jboss.web.WebService"

. . .

<attribute name="Port">
         <!-- Get the port to use from ServiceBindingManager. -->
         8085
</attribute>

. . .

</mbean>

Try to restart the application server. If the error appears again, you can leave the line as was before.

martin5211 37 Posting Whiz in Training

Do you have insert privileges into that database?

martin5211 37 Posting Whiz in Training

Use length() with strings. The library Apache Commons Lang provides isNumeric() to check strings. I'll give you an example, don't forget to download and add this external jar into your project:

import org.apache.commons.lang.StringUtils;

public class StringTest {

	public static void main(String[] args) {
		String s = "12345";
		
		System.out.println(s.length());
		if(StringUtils.isNumeric(s)) System.out.println("The string is numeric");;
	}

}
martin5211 37 Posting Whiz in Training

Appears to be something related with encoding... There is missing two parenthesis at the end. Some array exceeded the length. I did correct indentation with Eclipse, looks better now.

martin5211 37 Posting Whiz in Training

An extremely complex filter maybe could perform a domain check and a smtp validation but that can be slow... and that could take time to develop.

martin5211 37 Posting Whiz in Training

That happens because before <% if (s != null && s.equals("Songs")) out.println("selected=\"selected\""); %> there is an extra > symbol, needs to be removed on each case.

martin5211 37 Posting Whiz in Training

Remove Selected="True" and add > after the value on line 4

martin5211 37 Posting Whiz in Training
<% if s != null && (s.equals("Songs"))

There's a missing parenthesis, should be:

<% if (s != null && s.equals("Songs"))

Do the same in the other cases.

martin5211 37 Posting Whiz in Training

Add s != null && before s.equals("Option3") on each condition

martin5211 37 Posting Whiz in Training

It's easy, use a condition on each option.

<% String s = (String) request.getAttribute("subState"); %>
    <option value=""><fmt:message key="help.text.choose"/></option>
    <option value="Help" <% if (s.equals("Help")) out.println("selected=\"selected\""); %>><fmt:message key="help.text.help"/></option>
    <option value="Other" <% if (s.equals("Other")) out.println("selected=\"selected\""); %>><fmt:message key="help.text.other"/></option>

Instead of using RequestDispatcher object in ContactServlet for the success page, redirect to the same contact form, send an attribute with request.setAttribute() , then finally in the contact form is practical to use a condition (check the attribute isn't null), to display the message.

martin5211 37 Posting Whiz in Training

I'm sorry, I forgot to add test(email) in the condition that send the email.

package net.sourceforge.subsonic.controller;

import java.io.IOException;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.mail.*;
import javax.mail.internet.*;

public class ContactServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
	
		
	String email = request.getParameter("email");
	String subject = request.getParameter("subject");
	String message = request.getParameter("message");
		
	request.setAttribute("emailState", email);
	request.setAttribute("subState", subject);
	request.setAttribute("msgState", message);
	
	if (email.isEmpty()){
		request.setAttribute("err_email", "Please proivde a email");
	}
	if (!test(email)){
		request.setAttribute("err_email", "Provided incorrect email");
	}
	if (message.isEmpty()){
		request.setAttribute("err_msg", "Please provide a message");
	}
	if (subject.isEmpty()){
		request.setAttribute("err_sub", "Please provide a subject");
	}
	
		
		if(!email.isEmpty() && !message.isEmpty() && !subject.isEmpty() && test(email)){
			Properties props = new Properties();
			props.put("mail.smtp.host", "mysmptserver.com");
			props.put("mail.smtp.port", "587");
			
	        	Session session = Session.getDefaultInstance(props, null);
			
		try {
	                Message m = new MimeMessage(session);
	                m.setFrom(new InternetAddress(email, ""));
	                m.addRecipient(Message.RecipientType.TO, new InternetAddress("myadress@mydomain.com", ""));
	                m.setSubject(subject);
	                m.setText(message);
	                Transport.send(m);

	        } catch (AddressException e) {
	        	e.printStackTrace();
	        } catch (javax.mail.MessagingException e) {
		        e.printStackTrace();
		}
	        
		RequestDispatcher view = request.getRequestDispatcher("success.jsp");
			
		view.forward(request, response);
		
			}else{
		RequestDispatcher view = request.getRequestDispatcher("contact.jsp");
			
		view.forward(request, response);
			
			

		}
	}
	public static boolean test(String str){
		String reg = "[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})";
		Pattern p = Pattern.compile(reg);
		Matcher m = p.matcher(str);
		while(m.find())
		{
			String s1 = m.group(0);
			if (str == s1) return true;
		}

		return false;
	}

}

Contact form:

<form action="Contact.do" method="get">
    <p>Your email address: <input name="email" value="<% if(request.getAttribute("emailState") != null) out.println(request.getAttribute("emailState")); %>"></p><% if(request.getAttribute("err_email") != null) out.println(request.getAttribute("err_email")); %>
    <p>Mail subject: <input name="subject" value="<% if(request.getAttribute("subState") != null) out.println(request.getAttribute("subState")); %>"><% if(request.getAttribute("err_sub") != null) out.println(request.getAttribute("err_sub")); %></p>
    <p>Mail message: <textarea name="message"><% if(request.getAttribute("msgState") != null) out.println(request.getAttribute("msgState")); %></textarea><% if(request.getAttribute("err_msg") != null) out.println(request.getAttribute("err_msg")); %></p>
    <p><input type="submit"></p>
</form>
martin5211 37 Posting Whiz in Training

To save the information of each field use request.setAttribute("emailState", email) and then out.println(request.getAttribute("emailState")) on the input value (contact form), very similar to the procedure to pass errors.

martin5211 37 Posting Whiz in Training

There is missing two imports. Place the methods aside, not inside.

package net.sourceforge.subsonic.controller;

import java.io.IOException;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.mail.*;
import javax.mail.internet.*;

public class ContactServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
	
		
	String email = request.getParameter("email");
	String subject = request.getParameter("subject");
	String message = request.getParameter("message");
		
	if (email.isEmpty()){
		request.setAttribute("err_email", "Please proivde a email");
	}
	if (!test(email)){
		request.setAttribute("err_email", "Provided incorrect email");
	}
	if (message.isEmpty()){
		request.setAttribute("err_msg", "Please provide a message");
	}
	if (subject.isEmpty()){
		request.setAttribute("err_sub", "Please provide a subject");
	}
	
		
		if(!email.isEmpty() && !message.isEmpty() && !subject.isEmpty()){
			Properties props = new Properties();
			props.put("mail.smtp.host", "mysmptserver.com");
			props.put("mail.smtp.port", "587");
			
	        	Session session = Session.getDefaultInstance(props, null);
			
		try {
	                Message m = new MimeMessage(session);
	                m.setFrom(new InternetAddress(email, ""));
	                m.addRecipient(Message.RecipientType.TO, new InternetAddress("myadress@mydomain.com", ""));
	                m.setSubject(subject);
	                m.setText(message);
	                Transport.send(m);

	        } catch (AddressException e) {
	        	e.printStackTrace();
	        } catch (javax.mail.MessagingException e) {
		        e.printStackTrace();
		}
	        
		RequestDispatcher view = request.getRequestDispatcher("donate.view");
			
		view.forward(request, response);
		
			}else{
		RequestDispatcher view = request.getRequestDispatcher("help.view");
			
		view.forward(request, response);
			
			

		}
	}
	public static boolean test(String str){
		String reg = "[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})";
		Pattern p = Pattern.compile(reg);
		Matcher m = p.matcher(str);
		while(m.find())
		{
			String s1 = m.group(0);
			if (str == s1) return true;
		}

		return false;
	}

}
martin5211 37 Posting Whiz in Training

I forgot the i letter on line 8. Place that method after doGet. Use the following conditional after email.isEmpty() condition.

if (!test(email)){
		request.setAttribute("err_email", "Provided incorrect email");
	}
martin5211 37 Posting Whiz in Training

Here is the example, use it into a conditional. I extracted the pattern from http://www.mkyong.com/regular-expressions/how-to-validate-email-address-with-regular-expression/

public static boolean test(String str){
		String reg = "[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})";
		Pattern p = Pattern.compile(reg);
		Matcher m = p.matcher(str);
		while(m.find())
		{
			String s1 = m.group(0);
			if (str == s1) return true;
		}

		return false;
	}
martin5211 37 Posting Whiz in Training

That's more difficult, you need a static method that does an email extraction using regular expressions (Regex) and return a boolean.

Just another suggestion, you can also store the values of each field on request parameters and pass it to each input field to remember the content.

martin5211 37 Posting Whiz in Training

There is an extra parenthesis on message.isEmpty() call.

if(!email.isEmpty() && !message.isEmpty()) && !subject.isEmpty()){
martin5211 37 Posting Whiz in Training

Could you be more specific? Are you using out.println(request.getAttribute("err_msg")) on the contact form?

martin5211 37 Posting Whiz in Training

Both are almost the same code...

String email = request.getParameter("email");
	String subject = request.getParameter("subject");
	String message = request.getParameter("message");
		
	if (email.isEmpty()){
		request.setAttribute("err_email", "Email is empty");
	}
	if (message.isEmpty()){
		request.setAttribute("err_msg", "Message is empty");
	}

	if(!email.isEmpty() && !message.isEmpty()){
	...
	}else{
		RequestDispatcher view = request.getRequestDispatcher("contact.jsp");
			
		view.forward(request, response);
			
	}
martin5211 37 Posting Whiz in Training

Well, we're validating if the message is null. It's possible to add more fields on that condition and an else clause to redirect to the form again. Also, would be nice to pass a request parameter to the jsp.

import java.io.IOException;
import java.util.Properties;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.mail.*;
import javax.mail.internet.*;

public class ContactServlet extends HttpServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
		
		String email = request.getParameter("email");
		String subject = request.getParameter("subject");
		String message = request.getParameter("message");
		
		if(!message.isEmpty()){
			String host = "smtp.gmail.com";
	    		int port = 587;
	    		String username = "*** your Gmail username ***";
	    		String password = "*** your Gmail password ***";
	    	
			Properties props = new Properties();
			props.put("mail.smtp.auth", "true");
	    		props.put("mail.smtp.starttls.enable", "true");
	        	Session session = Session.getDefaultInstance(props, null);
			
	        	String body = message;
	        
			try {
	         		Message m = new MimeMessage(session);
	       			m.setFrom(new InternetAddress(email, null));
	        		m.addRecipient(Message.RecipientType.TO, new InternetAddress("destination@example.com", "me"));
	        		m.setSubject(subject);
	          		m.setText(body);
	            
	          		Transport transport = session.getTransport("smtp");
	    	  		transport.connect(host, port, username, password);
	     
	    	 		Transport.send(m);

	        	} catch (AddressException e) {
	        		e.printStackTrace();
	        	} catch (javax.mail.MessagingException e) {
				e.printStackTrace();
			}
	        
			RequestDispatcher view = request.getRequestDispatcher("success.jsp");
			view.forward(request, response);

		}else{
			request.setAttribute("error", "Message is empty");
			
			RequestDispatcher view = request.getRequestDispatcher("contact.jsp");  // return to contact form
			view.forward(request, response);
			
		}
	}

}

Use out.println(request.getAttribute("error")) on the contact form to show the error. A better alternative would be:

<p>Mail message: <textarea name="message"></textarea>
<% if (request.getAttribute("error") != null) out.println(request.getAttribute("error")); %></p>
martin5211 37 Posting Whiz in Training

Another alternative, is to use Gmail as mail transport agent, with some modifications of the code:

import java.io.IOException;
import java.util.Properties;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.mail.*;
import javax.mail.internet.*;

public class ContactServlet extends HttpServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
		
		String email = request.getParameter("email");
		String subject = request.getParameter("subject");
		String message = request.getParameter("message");
		
		if(!message.equals(null)){
			String host = "smtp.gmail.com";
	    	int port = 587;
	    	String username = "*** your Gmail username ***";
	    	String password = "*** your Gmail password ***";
	    	
			Properties props = new Properties();
			props.put("mail.smtp.auth", "true");
	    	props.put("mail.smtp.starttls.enable", "true");
	        Session session = Session.getDefaultInstance(props, null);
			
	        String body = message;
	        
		try {
	        	Message m = new MimeMessage(session);
	        	m.setFrom(new InternetAddress(email, null));
	        	m.addRecipient(Message.RecipientType.TO, new InternetAddress("destination@example.com", "me"));
	        	m.setSubject(subject);
	        	m.setText(body);
	            
	        	Transport transport = session.getTransport("smtp");
	    		transport.connect(host, port, username, password);
	     
	    		Transport.send(m);

	        } catch (AddressException e) {
	        	e.printStackTrace();
	        } catch (javax.mail.MessagingException e) {
				e.printStackTrace();
			}
	        
			RequestDispatcher view = request.getRequestDispatcher("success.jsp");
			
			view.forward(request, response);

		}
	}

}
martin5211 37 Posting Whiz in Training

Yes, a SMTP server is missing according to the first line.

martin5211 37 Posting Whiz in Training

Can you give the complete stack trace of the error?

martin5211 37 Posting Whiz in Training

That's weird, works flawlessly in my computer. In most cases, you need to configure Postfix or Sendmail to accept incoming email through port 25.

martin5211 37 Posting Whiz in Training

Have you tried OpenCMS at http://www.opencms.org/? It's truly open source.