login .jsp
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Devmanuals.com-Hello World Struts Tutorial</title>
</head>
<body>
<h2>Struts 2 Login Example</h2>
<s:actionerror />
<s:form action="login" method="post" enctype="multipart/form-data">
<s:textfield name="username" key="username" size="20" />
<s:password name="password" key="password" size="20" />
<s:file name="myFile" key="myFile" />
<s:submit value="upload" align="center" />
</s:form>
</body>
</html>
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!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.enable.DynamicMethodInvocation"
value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.custom.i18n.resources"
value="ApplicationResources" />
<constant name="struts.multipart.saveDir" value="C:/Users/satbir/Desktop/apache-tomcat-7.0.40/work" />
<package name="default" extends="struts-default" namespace="/">
<action name="login" class="com.devmanuals.LoginAction">
<interceptor-ref name="basicStack"></interceptor-ref>
<interceptor-ref name="fileUpload">
<param name="maximumSize">10240</param>
<param name="allowedTypes">text/html</param>
</interceptor-ref>
<result name="success">Welcome.jsp</result>
<result name="error">Login.jsp</result>
</action>
</package>
</struts>
LoginAction.java
package com.devmanuals;
import java.io.File;
import org.apache.commons.io.FileUtils;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction {
private String username;
private String password;
private File myFile;
private String myFileContentType;
private String myFileFileName;
private String destPath;
public String execute() {
String nm= getMyFileContentType();
System.out.println("Src File name: " + nm);
System.out.println("Dst File name: " + myFileFileName);
try
{
if (this.username.equals("user")
&& this.password.equals("user007")) {
destPath = "C:/Users/satbir/Desktop/apache-tomcat-7.0.40/work";
System.out.println("Src File name: " + this.myFile);
System.out.println("Dst File name: " + myFileFileName);
System.out.println("Dst File name: " + myFileContentType);
System.out.println(" name: " + username);
File destFile = new File(destPath, this.myFileFileName);
FileUtils.copyFile(this.myFile, destFile);
return "success";
}
else {
//addActionError(getText("error.login"));
return "error";
}
}
catch (Exception e)
{
System.out.println(e);
}
return "success";
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public File getMyFile() {
return myFile;
}
public void setMyFile(File myFile) {
this.myFile = myFile;
}
public String getMyFileContentType() {
return myFileContentType;
}
public void setMyFileContentType(String myFileContentType) {
this.myFileContentType = myFileContentType;
}
public String getMyFileFileName() {
return myFileFileName;
}
public void setMyFileFileName(String myFileFileName) {
this.myFileFileName = myFileFileName;
}
}
console :
Jun 01, 2013 10:38:59 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre7/bin/client;C:/Program Files/Java/jre7/bin;C:/Program Files/Java/jre7/lib/i386;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files\Java\jdk1.7.0_13\bin;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Nmap;E:\eclipse;;.
Jun 01, 2013 10:38:59 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Struts2Login' did not find a matching property.
Jun 01, 2013 10:39:00 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jun 01, 2013 10:39:00 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Jun 01, 2013 10:39:00 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1106 ms
Jun 01, 2013 10:39:00 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jun 01, 2013 10:39:00 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.40
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Parsing configuration file [struts-default.xml]
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Unable to locate configuration files of the name struts-plugin.xml, skipping
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Parsing configuration file [struts-plugin.xml]
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Parsing configuration file [struts.xml]
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.ObjectFactory)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.FileManagerFactory)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.XWorkConverter)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.CollectionConverter)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.ArrayConverter)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.DateConverter)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.NumberConverter)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.StringConverter)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ConversionPropertiesProcessor)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ConversionFileProcessor)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ConversionAnnotationProcessor)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.TypeConverterCreator)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.TypeConverterHolder)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.TextProvider)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.LocaleProvider)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.ActionProxyFactory)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ObjectTypeDeterminer)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (org.apache.struts2.dispatcher.mapper.ActionMapper)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (jakarta) for (org.apache.struts2.dispatcher.multipart.MultiPartRequest)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (org.apache.struts2.views.freemarker.FreemarkerManager)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (org.apache.struts2.components.UrlRenderer)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.validator.ActionValidatorManager)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.util.ValueStackFactory)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.util.reflection.ReflectionProvider)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.util.reflection.ReflectionContextFactory)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.util.PatternMatcher)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (org.apache.struts2.dispatcher.StaticContentLoader)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.UnknownHandlerManager)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (org.apache.struts2.views.util.UrlHelper)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Choosing bean (struts) for (com.opensymphony.xwork2.util.TextParser)
Jun 01, 2013 10:39:02 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Loading global messages from [ApplicationResources]
Jun 01, 2013 10:39:02 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jun 01, 2013 10:39:02 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jun 01, 2013 10:39:02 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2422 ms
***********************************************************************
* WARNING!!! *
* *
* >>> FilterDispatcher <<< is deprecated! Please use the new filters! *
* *
* This can be a source of unpredictable problems! *
* *
* Please refer to the docs for more details! *
*
http://struts.apache.org/2.x/docs/webxml.html *
* *
***********************************************************************
Jun 01, 2013 10:39:15 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
WARNING: No configuration found for the specified action: 'login' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
Jun 01, 2013 10:39:16 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
WARNING: No configuration found for the specified action: 'login' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
***********************************************************************
* WARNING!!! *
* *
* >>> FilterDispatcher <<< is deprecated! Please use the new filters! *
* *
* This can be a source of unpredictable problems! *
* *
* Please refer to the docs for more details! *
*
http://struts.apache.org/2.x/docs/webxml.html *
* *
***********************************************************************
Src File name: null
Dst File name: null
Src File name: null
Dst File name: null
Dst File name: null
name: user
java.lang.NullPointerException