Struts2 - getting 404 Resource Unavailable error from request page - java

I'm trying to write a login example that takes the user to a success.jsp if username equals password and an error message if it doesn't. The error message works but success (username=password) results in a 404 (HTTP Status 404 - /Struts2Ch4/success.jsp)
I experienced a similar problem in a previous post. I had not declared the RESULT parameter in the class. I was advised to use annotations in the class file and this solved the problem. In this case both the success and result parameters seem to be declared by the class so I'm not sure why I'm getting 404.
alias.jsp
<%# page language="java" pageEncoding="ISO-8859-1"%>
<%# taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title><s:text name="app.title"/></title>
<link rel="stylesheet" href="mystyle.css" type="text/css" />
</head>
<body>
<table align="center" width="300">
<tr>
<td colspan="2"><s:actionerror/></td>
</tr>
<tr><td align="center" colspan="2">Enter Login ID and Password</td></tr>
<tr><td align="center">
<s:form action="aliasing" method="post">
<s:textfield name="uname" key="app.loginid"/>
<s:password name="pwd" key="app.password"/>
<s:submit value="Enter"/>
</s:form>
</td>
</tr>
<tr><td align="center" colspan="2">
B a c k</td>
</tr>
</table>
</body>
</html>
struts.xml
<!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" extends="struts-default">
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="exception"/>
</global-exception-mappings>
<action name="aliasing" class="com.manaar.action.AliasAction">
<param name="aliases">#{ 'uname' : 'loginid','pwd' : 'password' }</param>
<interceptor-ref name="alias"/>
<interceptor-ref name="basicStack"/>
<result name="success">/success.jsp</result>
<result name="error">/alias.jsp</result>
<result name="input">/alias.jsp</result>
</action>
</package>
</struts>
AliasAction.java
package com.manaar.action;
import com.opensymphony.xwork2.ActionSupport;
public class AliasAction extends ActionSupport {
private String loginid;
private String password;
public String getLoginid() {
return loginid;
}
public void setLoginid(String loginid) {
this.loginid = loginid;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String execute() throws Exception {
System.out.println("Login Id: "+getLoginid());
System.out.println("Password: "+getPassword());
if(loginid.equals(password))
return SUCCESS;
else{
this.addActionError(getText("app.invalid"));
return ERROR;
}
}
}
success.jsp
<%# page language="java" pageEncoding="ISO-8859-1"%>
<%# taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><title><s:text name="app.title"/></title>
<link rel="stylesheet" href="mystyle.css" type="text/css" />
</head>
<body>
<div align="center">
<h1><s:text name="app.success"/></h1>
The action has returned SUCCESS as result code.<br><br>
Back to Index</div>
</body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org /2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com /xml/ns/javaee http://java.sun.com/xml/ns/javaee /web-app_3_0.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
index.jsp
<%# page language="java" pageEncoding="ISO-8859-1"%>
<%# taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"/>
<html>
<head><title><s:text name="app.title"/></title>
<link rel="stylesheet" href="mystyle.css" type="text/css" />
</head>
<body>
<table align="center" width=400>
<tr><td><h2>Sruts 2 Interceptors</h2></td></tr>
<tr><td><s:a href="alias.jsp">Interceptor Example 1</s:a></td></tr>
<tr><td>alias, basicStack </td></tr>
<tr><td> </td></tr>
<tr><td><s:a href="model.jsp">Interceptor Example 2</s:a></td></tr>
<tr><td>
exception, prepare, debugging, model-driven, params, conversionError, workflow
</td></tr>
<tr><td> </td></tr>
<tr><td>
<s:a href="servletAction.action">Interceptor Example 3</s:a>
</td></tr>
<tr><td>servlet-config, scoped-model-driven </td></tr>
<tr><td> </td></tr>
<tr><td><s:a href="longAction.action">Interceptor Example 4</s:a></td></tr>
<tr><td>completeStack, execAndWait</td></tr>
<tr><td> </td></tr>
<tr><td><s:a href="login.jsp">Interceptor Example 5</s:a> </td></tr>
<tr><td>basicStack, validation, workflow, scope </td></tr>
</table>
</body>
</html>

Related

Springboot. ModelAndView addObject is not replace a tag

My controller does not replace tags.
My controller has two endpoints URLs "/" and "/login"
#Controller
#RequestMapping(value={"/"})
public class Index {
#GetMapping("/")
public ModelAndView getLoginPageId() {
return new ModelAndView("login");
}
#GetMapping("/index")
public ModelAndView getLoginPageId(
#RequestParam("login") String login,
#RequestParam("password") String password
) {
ModelAndView modelAndView = new ModelAndView("index");
modelAndView.addObject("message", "123");
return modelAndView;
}
}
login.jsp
<html>
<head>
<title>login</title>
</head>
<body>
<form name="newUser" action="/index" method="get">
Login:<br>
<input type="text" name="login"><br>
Password:<br>
<input type="text" name="password"><br>
<br>
<input type="submit" value="Login">
</form>
</body>
</html>
index.jsp
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8"/>
</head>
<body>
<h1>My message ${message}</h1>
</body>
</html>
The Chrome browser gives response
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8"/>
<title>My Message ${message}</title>
</head>
<body>
<h1>HOA v ${message}</h1>
</body>
</html>
The ${message} is not replaced. I'm expecting ${message} should be replaced to 123.
What do I need to change?
Try to add <%# page isELIgnored="false" %> it will enable EL:
Have a look at:
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<%# page isELIgnored="false" %>
<meta charset="UTF-8"/>
<title>My Message ${message}</title>
</head>
<body>
<h1>HOA v ${message}</h1>
</body>
</html>
Alternatively you could add <el-ignored>false</el-ignored> to 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_2_5.xsd" version="2.5">
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<el-ignored>true</el-ignored>
</jsp-property-group>
</web-app>

Error of Null Pointer Exception in java using struts [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 5 years ago.
I am trying to retrieve data from database but i am getting Null Pointer Exception in struts.I am using ecllipse mars.
Thanks in advance
My files are:-
web.xml
enter code here
<?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" version="3.0">
<display-name>Report2</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
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="myapp" />
<package name="default" extends="struts-default" namespace="/">
<action name="database" class="genius.database.ReportAction"
method="execute">
<result name="Success">/ReportView.jsp</result>
</action>
</package>
</struts>
ReportAction.java
package genius.database;
import java.sql.*;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import genius.database.Student;
public class ReportAction{
HttpServletRequest request=null;
public String execute() throws SQLException,ClassNotFoundException {
Connection con;
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/registertable?
zeroDateTimeBehavior=convertToNull","root","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from student");
List<Student> li=null;
li=new ArrayList<Student>();
while(rs.next()){
Student st=new Student();
st.setRno(rs.getInt(1));
st.setName(rs.getString(2));
st.setEng(rs.getInt(3));
st.setMaths(rs.getInt(4));
li.add(st);
}
request.setAttribute("disp", li);
return "Success";
}
}
Student.java
package genius.database;
public class Student {
private int rno;
private String name;
private int eng;
private int mat;
public int getRno() {
return rno;
}
public void setRno(int rno) {
this.rno = rno;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getEng() {
return eng;
}
public void setEng(int eng) {
this.eng = eng;
}
public int getMaths() {
return mat;
}
public void setMaths(int mat) {
this.mat = mat;
}
}
ReportView.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib prefix="s" uri="/struts-tags" %>
<%#page language="java" import="java.util.*" %>
<%#page language="java" import="genius.database.Student" %>
<%#page language="java" import="genius.database.ReportAction" %>
<!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>
<h2>Report</h2>
<s:actionerror key="error.Insert"/>
<s:form name="form" method="post">
<table border="1">
<thead>
<tr>
<td>Roll No</td>
<td>Name</td>
<td>Eng</td>
<td>Maths</td>
</tr>
</thead>
<tbody>
<tr>
<%
List<Student> li=(List<Student>)request.getAttribute("disp");
out.println(li);
if(li==null){
Iterator<Student> it=li.iterator();
while(it.hasNext()){
Student st=(Student)it.next();
int rno=st.getRno();
String name=st.getName();
int eng=st.getEng();
int mat=st.getMaths();
%>
<td><%out.println(rno);%></td>
<td><%out.println(name);%></td>
<td><%out.println(eng);%></td>
<td><%out.println(mat);%></td>
<% }
}
%>
</tr>
</tbody>
</table>
</s:form>
</body>
</html>
index.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib prefix="s" uri="/struts-tags" %>
<!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>Report</title>
</head>
<body>
<s:form action="database.action">
<s:submit value="Submit"></s:submit>
</s:form>
</body>
</html>
You probably mean:
if (li!=null)
From
if(li==null){
Iterator<Student> it=li.iterator();
while(it.hasNext()){
Student st=(Student)it.next();
int rno=st.getRno();
String name=st.getName();
int eng=st.getEng();
int mat=st.getMaths();
Not sure if that's it, but that will definitely cause a NullPointerException.
Better to use JSTL rather than scriplets in you JSP
e.g.
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
....
<c:forEach items="${disp}" var="student" >
${student.rno}
${student.name}
</c:forEach>
see https://www.tutorialspoint.com/jsp/jsp_standard_tag_library.htm

Spring unable to get form values

Im using the below servlet to get the form values, when the form is posted im able to get the username and password but unable to access it in the mainpage.jsp which displays the username/password.
Servlet
package com.school.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.school.beans.Login;
#Controller
public class Logincontroller {
#RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView login() {
return new ModelAndView("login", "loginform", new Login());
}
#RequestMapping(value = "/validatelogin", method = RequestMethod.POST)
public String validatelogin(#ModelAttribute("SchoolManagement")Login login,
ModelMap model) {
model.addAttribute("username", login.getUsername());
model.addAttribute("password", login.getPassword());
System.out.println("useranme = " + login.getUsername());
System.out.println("password = " + login.getPassword());
return "mainpage";
}
}
login.jsp
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<!--
<script src="javascript/login.js"></script>
<link rel="stylesheet" type="text/css" href="css/login.css"/>
http://www.mkyong.com/spring-mvc/spring-mvc-how-to-include-js-or-css-files-in-a-jsp-page/
-->
<!--<script src="<c:url value="/resources/js/jquery.1.10.2.min.js" />"></script>-->
<link href="<c:url value="/resources/css/login.css" />" rel="stylesheet">
<script src="<c:url value="/resources/js/login.js" />"></script>
<script
src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<div id="top"></div>
<div id="middle">
<form:form method="POST" id="loginform" commandName="loginform"
action="/SchoolManagement/validatelogin">
<form:label path="username"> Username:</form:label>
<form:input path="username" /> <br>
<form:label path="password"> Password:</form:label>
<form:input path="password" />
<input type="submit" value="submit">
</form:form>
</div>
<div id="bottom"></div>
</body>
</html>
mainpage.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!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>MainPage</title>
</head>
<body>
<h2>Submitted Student Information</h2>
<table>
<tr>
<td>Name</td>
<td>${username}</td>
</tr>
<tr>
<td>Password</td>
<td>${password}</td>
</tr>
</table>
</body>
</html>
Try getting the values directly out of the request.
<%
String username = (String) request.getAttribute("username");
String password = (String) request.getAttribute("password");
%>
<table>
<tr>
<td>Name</td>
<td><%= username %></td>
</tr>
<tr>
<td>Password</td>
<td><%= password %></td>
</tr>
</table>
That should definitely work... if not, something's wrong with the setup.
your command name
commandName="loginform"
is different than model attribute
#ModelAttribute("SchoolManagement")
try to use same names

Spring application is giving two different URLs in two different time

I am developing a Spring application that will do a basic CRUD operation.The login and after login the population of information is working properly.But when i trying to forward to a page from the main page i.e from where all the information is coming.The URL that is coming is strange and i can not find a reason behind that.i am posting my full code here...
web.xml
<display-name>SpringWebCrudExample</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/forms/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
">
<!-- Enable annotation driven controllers, validation etc... -->
<mvc:annotation-driven />
<context:component-scan base-package="com.gamma.controller" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
index.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
login.jsp
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!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>
Login Page
<form:form action="forms/doLogin" commandName="loginForm">
<table>
<tr>
<td>UserName:</td>
<td><form:input path="username" /></td>
</tr>
<tr>
<td>Password:</td>
<td><form:input path="password" /></td>
</tr>
<tr>
<td><input type="submit" value="Submit" /></td>
</tr>
</table>
</form:form>
</body>
</html>
mainpage.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!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>
main page is here all details will be shown here...
<c:url var="addUrl" value="/add" />
<table style="border: 1px solid; width: 500px; text-align:center">
<thead style="background:#fcf">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Address</th>
<th colspan="3"></th>
</tr>
</thead>
<td>Add</td>
<tbody>
<c:forEach items="${mainpage}" var="student">
<tr>
<td><c:out value="${student.fname}" /></td>
<td><c:out value="${student.lname}" /></td>
<td><c:out value="${student.address}" /></td>
</tr>
</c:forEach>
</tbody>
</table>
</body>
</html>
AppController
#Controller
public class AppController {
public static DbImpl dbImpl;
#RequestMapping(value = "/start", method = RequestMethod.GET)
public static ModelAndView getAllinfo() {
ModelAndView mav = new ModelAndView("/mainpage");
System.out.println("mainpage is here");
List<StudentVO> allInfo = dbImpl.populateInfo();
System.out.println("The List is " + allInfo.size());
mav.addObject("mainpage", allInfo);
return mav;
}
#RequestMapping(value = "/doLogin", method = RequestMethod.GET)
public String ShowForm(Map model) {
LoginForm loginForm = new LoginForm();
model.put("loginForm", loginForm);
return "login";
}
#RequestMapping(value = "/doLogin", method = RequestMethod.POST)
public ModelAndView ProcessForm(#Valid LoginForm loginForm,
BindingResult result, Map model) {
String userName = "Jeet";
String passWord = "gamma";
if (result.hasErrors()) {
return new ModelAndView("login", "loginDetails", loginForm);
}
loginForm = (LoginForm) model.get("loginForm");
if (!loginForm.getUsername().equals(userName)
|| !loginForm.getPassword().equals(passWord)) {
return new ModelAndView("login", "loginDetails", loginForm);
}
model.put("loginForm", loginForm);
System.out.println("----->" + loginForm.getUsername());
RedirectView redirectView = new RedirectView("start", true);
return new ModelAndView(redirectView);
}
#RequestMapping(value="/add",method=RequestMethod.GET)
public String aMethod2insert(Map model){
StudentVO studentVO=new StudentVO();
model.put("studentVO", studentVO);
return "insertpage";
}
Now the problem is that when i am doing the login it is working fine and it is generating the URL SpringWebCrudExample/forms/start and coming to this page (the picture i attached here).Now i have added a link call add in this page from which i will go to a page where i will insert some vlaues, but the problem is here when i click on this URL it is giving SpringWebCrudExample/add this URL.As the result the page is not coming.
It has nothing to do with spring but with basic URL generation.
When you are prefixing a href with a / it means that this is an absolute URL and it will be navigated from the root of your application. If you leave it out it will be relative to the current URL.
Now lets take an application deployed at /app which has a servlet mapped at /servlet. If you are in a page at /app/servlet/page and you have a href like /foo it will result in the actual location of /app/foo. Leaving the / would lead to /app/servlet/foo.
For more information see Absolute vs relative URLs

Struts 2 Action Error - Doesn't proceed to the next page

These are the files that I have created along with the AccessDenied.jsp and HelloWorld.jsp, but the code doesn't run.
package com.Struts;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorldActionSupport extends ActionSupport {
private String name;
public HelloWorldActionSupport() {
}
#Override
public String execute() throws Exception
{
if("SECRET".equals(name))
{
return SUCCESS;
}
else
{
return ERROR;
}
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Struts.xml File:
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<!-- Configuration for the default package.
<constant name="struts.devMode" value="true"/>
<package name="hello" extends="struts-default">
<action name="helloWorldActionSupport" class= "com.Struts.HelloWorldActionSupport">
<result name="success">/HelloWorld.jsp</result>
<result name="error">/AccessDenied.jsp</result>
</action>
</package>
</struts>
index.jsp File:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#taglib prefix="s" uri="/struts-tags" %>
<!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=UTF-8">
<title>Hello World</title>
</head>
<body>
<h1>Hello World from Struts-2</h1>
<s:action name="helloWorldActionSupport" executeResult="true">
<label for="name">Please Enter Your Name: </label><br/>
<input type="text" name="name"/>
<input type="submit" value="Say Hello"/>
</s:action>
</body>
</html>
After I click on the submit button it doesn't proceed to the next page.
Use this code
<s:form action="helloWorldActionSupport" method="POST">
<label for="name">Please Enter Your Name: </label><br/>
<input type="text" name="name"/>
<input type="submit" value="Say Hello"/>
</s:form>

Categories

Resources