Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Struts
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830
this week in the
Programmer Certification
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Struts
HTTP Status 404 - /Structs-Doc-2/Login.jsp
Prakash Rai
Ranch Hand
Posts: 107
I like...
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Web.xml ====== <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>Structs-Doc-2</display-name> <welcome-file-list> <welcome-file>login.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
Struts-config.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"> <struts-config> <form-beans> <form-bean name="loginForm" type="com.jtcindia.struts.LoginForm" /> </form-beans> <action-mappings> <action path="/LoginSubmit" name="loginForm" type="com.jtcindia.struts.action.LoginAction" input="/Login.jsp"> <forward name="home" path="/home.jsp" /> <forward name="login" path="/Login.jsp" /> </action> </action-mappings> <message-resources parameter="com.jtcindia.struts.messages" /> </struts-config>
login.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib prefix="html" uri="http://jakarta.apache.org/struts/tags-html"%> <!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=ISO-8859-1"> <title>Strut-1 Login.jsp</title> </head> <body> <html:form action="LoginSubmit"> <center> <table align="center"> <tr> <td align="center" colspan="3"><font color="red" size='5'>${MSG}</font></td> </tr> <tr> <td colspan="3" align="center"><font size='5' face="ARIAL">Account Login</font></td> </tr> <tr> <td><h1>User Name :</h1></td> <td><html:text property="username" /></td> <td><html:errors property="username" /></td> </tr> <tr> <td><h1>Password</h1></td> <td><html:password property="password" /></td> <td><html:errors property="password" /></td> </tr> <tr> <td colspan="3" align="center"><html:submit value="Login" /></td> </tr> </table> </center> </html:form> </body> </html>
home.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!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=ISO-8859-1"> <title>Insert title here</title> </head> <body> <h1> <center> Hello <font color="blue">${UN} </font><br> Home Page </center> </h1> </body> </html>
LoginForm.Java
package com.jtcindia.struts; import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; public class LoginForm extends ActionForm { private String username = "Abc"; private String password; 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; } @Override public void reset(ActionMapping mapping, ServletRequest request) { this.username = null; this.password = null; } public ActionErrors validate(ActionMapping am, HttpServletRequest req) { System.out.println("ActionErrors validate(ActionMapping am,HttpServletRequest req)"); ActionErrors errors = new ActionErrors(); if (username == null || username.length() == 0) { System.out.println("IN Action Form****\n"); errors.add("username", new ActionError("errors.un.required")); } if (password == null || password.length() == 0) { errors.add("password", new ActionError("errors.pw.required")); } System.out.println("Hello Testing LoginForm"); return errors; } }
LoginAction.java
package com.jtcindia.struts.action; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import com.jtcindia.struts.LoginForm; public class LoginAction extends Action { public ActionForward execute(ActionMapping am, ActionForm af, HttpServletRequest request, HttpServletResponse response) { System.out.println( "ActionForward execute(ActionMapping am,ActionForm af,HttpServletRequest request,HttpServletResponse response)"); LoginForm lf = (LoginForm) af; String un = lf.getUsername(); String pw = lf.getPassword(); String result = ""; if (un.equals(pw)) { System.out.println("Checking the Result*****\n"); result = "home"; request.setAttribute("UN", un); } else { result = "login"; String msg = "Invalid Username or password"; request.setAttribute("MSG", msg); } ActionForward forward = am.findForward(result); return forward; } }
On Browser:
========
HTTP Status 404 - /Structs-Doc-2/Login.jsp
Joe Ess
Bartender
Posts: 9626
16
I like...
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Do you have a file with that name?
HTTP Status 404 - /Structs-Doc-2/Login.jsp
[
How To Ask Questions On JavaRanch
]
Bras cause cancer. And tiny ads:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Error creating form bean in a simple struts application
Login App getting redirected back to login page after login
help with login program
exception in uploading the file
Weblogic deployment problem
More...