0 Replies - 566 Views - Last Post: 13 May 2017 - 08:10 AM

#1 Catalinaeva1  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 13-May 17

Help Creating a Simple Login Page Using Eclipse/Maven

Posted 13 May 2017 - 08:10 AM

Hello,


Sorry to bother everyone, but I'm new to using Java with Eclipse. I'm working with struts in Maven, and I'm trying to create a simple login page where a user enters his/her username and password; then when he/she hits the submit or login button, it redirects them to another page (e.g. welcome page). I'm having trouble getting this to happen because when I run the code in Apache server using Tomcat 7, I keep getting a 404 error saying "There is no action mapped for namespace [/] and action named [Welcome] associated with context path [/myapp]. I read that this has to do with my path being incorrect in the struts.xml file. Can anyone help me fix my code since I'm super new to struts and have been searching tutorials to help me out. I've also attached the zip file.

Here's my code below:

Pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0/>/>.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.codebehind</groupId>
  <artifactId>myapp</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>myapp Maven Webapp</name>
  <url>http://maven.apache.org</url>
 <dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.struts</groupId>
			<artifactId>struts2-core</artifactId>
			<version>2.3.1.2</version>
		</dependency>
		<dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.4</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.0</version>
        <scope>provided</scope>
    </dependency> 
	</dependencies>
	<build>
		<finalName>Struts2Example</finalName>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.3.2</version>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>



LoginAction.java

package com.test;

public class LoginAction {

	private String username;
	private String password;

	public String getUsername() {
		return username;
	}
		
	public String getPassword(){
		return password;
		}

	public void setUsername(String username) {
		this.username = username;
	}
	
	
	public void setPassword(String password){
		this.password = password;
	}

	// all struts logic here
	public String execute() {

		return "SUCCESS";

	}





Login.jsp

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head></head>
<body>
	<h1>Employee Login Page</h1>

	<s:form action="Welcome">
		<s:textfield name="username" label="Username" />
		<s:password name="password" label="Password" />
		
		<s:submit />
	</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>

	<package name="default" namespace="/" extends="struts-default">
		<action name="Login">
			<result>/Login.jsp</result>
		</action>
		<action name="Welcome" class="com.test.LoginAction">
			<result name="SUCCESS">/welcome_user.jsp</result>
		</action>
	</package>

</struts>





web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
	<display-name>Struts 2 Web Application</display-name>

	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>
                org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
                </filter-class>
	</filter>

	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
<welcome-file-list>
<welcome-file>Login.jsp</welcome-file> 
</welcome-file-list>  
</web-app>




Any help is appreciated.

Is This A Good Question/Topic? 1
  • +

Page 1 of 1