JSP giving error: Requested resource not found - java

Just need a little help.
I tried to make a small test project but I'm stuck at this error. Having all my JAR files and JSPs well placed:
The requested resource (/LibrayManagement/list_of_books_available.jsp) is not available
Following is the jsp code :
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!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>Library</title>
</head>
<body>
<form action="Listofbooksaction" method="post">
<h3>List of books available</h3>
<c:forEach var = "list" items = "${requestScope.BooksList}">
<c:out value = "${list[0]}">
</c:out>
</c:forEach>
<input type= "submit" value = "get list">
</form>
</body>
</html>
Following is Action class code :
import java.sql.* ;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
public class Listofbooksaction extends HttpServlet {
private static final long serialVersionUID = 1L;
String url = "list_of_books_available.jsp";
public Listofbooksaction() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* #see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ConnectionsList c = new ConnectionsList() ;
try {
Statement St = c.createconnection();
ResultSet Rs = St.executeQuery("Select * from books_list") ;
System.out.println(Rs);
ArrayList<String> Books_List = new ArrayList<String>();
while(Rs.next())
{
Books_List.add(Rs.getString(1));
}
request.setAttribute("BooksList", Books_List);
response.sendRedirect(url);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Error Stacktrace:
java.lang.IllegalStateException org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:4‌​35) Listofbooksaction.doPost(Listofbooksaction.java:62) javax.servlet.http.HttpServlet.service(HttpServlet.java:637) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

Related

How should I send a parameter from jsp page to a servlet then to a jsp page then to a servlet?

I am trying to make a login form. and want the username parameter to accessed by the changepass.java file.
The flow of the application is:
login.jsp -> LoginServlet -> AfterLogin.jsp -> ChangePass.jsp -> ChangePassword Servlet
I tried using the session and request dispatcher for this it is not working.
I am able to get the parameter from login.jsp to ChangePass.jsp but after that the changePassword servlet is not able to access it.
My code for the flow is:
login.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<body>
<div align="center">
<form name="login" onsubmit="return onSubmit()" action="LoginServlet">
<h2 style="color:blue">Account Login</h2>
<table style="background-color:powderblue;border: 2px solid green;border-color:green;">
<tr><td>Enter User Name:</td><td><input type="text" name="username" minlength="6" required></td></tr>
<tr><td>Enter Pass Word:</td><td><input type="password" name="password" id="password" required></td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="login"></td></tr>
</table>
<br>
<u>Home</u>
</form>
</div>
<%
String msg=(String) request.getAttribute("msg");
if(msg!=null){
%>
<p style="color:red"><%=msg%></p>
<%
}
%>
<script type="text/javascript">
function onSubmit(){
var y=document.login.password.value;
var passR=/^(?=.*\d)(?=.*[A-Z]).{6,20}$/;
if(!y.match(passR)){
alert("Password must contain at least one number and one UpperCase letter");
document.getElementById("password").focus();
}
}
</script>
</body>
</html>
LoginServlet.java
package com.wipro.controller;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.wipro.util.DButil;
/**
* Servlet implementation class LoginServlet
*/
#WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* #see HttpServlet#HttpServlet()
*/
public LoginServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
try{
Connection con=DButil.getConnection();
PrintWriter out=response.getWriter();
String username=request.getParameter("username");
String password=request.getParameter("password");
String sql="select * from user_table where username=? and password=?";
PreparedStatement st=con.prepareStatement(sql);
st.setString(1, username);
st.setString(2, password);
ResultSet rs=st.executeQuery();
if(rs.next()) {
HttpSession se=request.getSession();
se.setAttribute("username", username );
request.getRequestDispatcher("AfterLogin.jsp").include(request, response);
}
else {
request.setAttribute("msg", "Invalid Credentials");
request.getRequestDispatcher("login.jsp").include(request, response);
}
}
catch(Exception e) {
e.printStackTrace();
}
}
/**
* #see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
AfterLogin.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1><font color=green> Welcome <%=session.getAttribute("username")%></font></h1>
Change Password
</body>
</html>
ChangePass.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<div align="center">
<form name="changePS" onsubmit="return onSubmit()" action="ChangePassword">
<%
String username=(String)session.getAttribute("username");
request.setAttribute("username", username);
%>
<h1><font color=green> Welcome <%=username%></font></h1>
<h2 style="color:blue">Change Password</h2>
<table style="background-color:powderblue;border: 2px solid green;border-color:green;">
<tr><td>Old Password:</td><td><input type="password" name="oldpwd" id="oldpwd" required></td></tr>
<tr><td>New Password:</td><td><input type="password" name="newpwd" id="newpwd" required></td></tr>
<tr><td>Confirm Password:</td><td><input type="password" name="confpwd" id="confpwd" required></td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="login"></td></tr>
</table>
<br>
<u>Home</u>
</form>
</div>
<script type="text/javascript">
function onSubmit(){
y=document.changePS.oldpwd.value;
z=document.changePS.newpwd.value;
a=document.changePS.confpwd.value;
passR=/^(?=.*\d)(?=.*[A-Z]).{6,20}$/;
if(z != a){
alert("New Password and Confirm Password do not match");
document.getElementById("confpwd").focus();
return false;
}
if(!y.match(passR)){
alert("Old Password must contain at least one number,one UpperCase letters");
document.getElementById("oldpwd").focus();
return false;
}
if(!z.match(passR)){
alert("New Password must contain at least one number,one UpperCase letters");
document.getElementById("newpwd").focus();
return false;
}
return true;
}
</body>
</html>
ChangePassword.java
package com.wipro.controller;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.wipro.util.DButil;
/**
* Servlet implementation class ChangePassword
*/
#WebServlet("/ChangePassword")
public class ChangePassword extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* #see HttpServlet#HttpServlet()
*/
public ChangePassword() {
super();
// TODO Auto-generated constructor stub
}
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
try{
Connection con=DButil.getConnection();
PrintWriter out=response.getWriter();
String username = (String)request.getAttribute("username");
String password=request.getParameter("newPwd");
String sql="update user_table set password=? where username=?";
PreparedStatement st=con.prepareStatement(sql);
st.setString(1, username);
st.setString(2, password);
int rs=st.executeUpdate();
if(rs!=0) {
out.println("<h1><font color=green> Updated the password </font></h1>");
}
else {
out.println("<h1><font color=red> Sorry no username with this name </font></h1>"+username);
}
}
catch(Exception e) {
e.printStackTrace();
}
}
/**
* #see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}

How to retrieve a volume parameter and making it display in result.jsp

I am really confused about this question. I have tried everything and nothing works.
I want to be able to get the volume and display it as param.volume. However it will return zero if I do it as a scriptlet.
I want to be able to create the getter method named getVolume that returns the volume of the cube when called (side * side * side).
My getter method is:
package servlets;
public class Cube {
private int side;
private int volume;
public void setVolume(int volume){
this.volume=volume;
}
public int getVolume() {
volume=side*side*side;
return volume;
}
public int getSide() {
return side;
}
public void setSide(int side) {
this.side = side;
}
}
In the CalcServlet:
package servlets;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class CalcServlet
*/
#WebServlet("/calc")
public class CalcServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String scube=request.getParameter("cube");
Cube obj=new Cube();
try{
int cube=Integer.parseInt(scube);
obj.setSide(cube);
obj.getVolume();
request.setAttribute("cube", obj);
}catch(NumberFormatException e){
}
ServletContext sc = this.getServletContext();
//RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/pages/result.jsp");
RequestDispatcher rd = sc.getRequestDispatcher ("/WEB-INF/pages/result.jsp");
rd.forward(request, response);
}
}
In result.jsp:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="c"
uri="http://java.sun.com/jsp/jstl/core" %>
<%# taglib tagdir="/WEB-INF/tags" prefix="myjsp" %>
<%# page import="servlets.Cube, servlets.CalcServlet " %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<body>
<h2>Cube Info Using JSP 2.0 </h2><br>
<b>Side of a Cube: ${param.side} </b><br>
<b>Volume of a Cube: ${param.side*param.side*param.side}</b><br>
<br></br><br>
Using Custom Tag:
<myjsp:displayform color="red"></myjsp:displayform>
<br></br><br>
<h2>Using JSTL:</h2>
<h2>Cube Info Using JSP 2.0 </h2><br>
<b>Side of a Cube: ${param.side} </b><br>
<b>Volume of a Cube: </b>
<c:choose>
<c:when test="${param.side*param.side*param.side>10}">
<li><span style="color: red;">Volume: ${param.side*param.side*param.side}</span></li>
</c:when>
<c:otherwise>
<li><span style="color: black;">Volume: ${param.side*param.side*param.side}</span></li>
</c:otherwise>
</c:choose>
</body>
</html>
The result displays because param.side is being read. However I want to do this with param.volume. Please help!! I have tried everything.
first fix your getter/setter for volume. right now your getter act like a setter.
public void setVolume(int Volume){
this.volume=volume;
}
public int getVolume() {
return volume;
}
then in your serlvet (proper pratice would be to do that in an utility class)
int side=Integer.parseInt(scube);
obj.setSide(side);
int volume= side*side*side;
obj.setVolume(volume);
request.setAttribute("cube", obj);
you named your parameter which contains the bean Cube "cube". On that line
request.setAttribute("cube", obj);
so to access the bean cube in your JSP you should do like that
${cube.side}
${cube.volume}
or the proper way
<c:out value="${cube.side}"/>
<c:out value="${cube.volume}"/>
For anyone who wants to know the answer, I got it from a friend. Hope this will benefit the community.
In result.jsp:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="c"
uri="http://java.sun.com/jsp/jstl/core" %>
<%# taglib tagdir="/WEB-INF/tags" prefix="myjsp" %>
<%# page import="servlets.Cube"%>
<%
Cube cube = (Cube) request.getAttribute("cube");
int side = 0, volume = 0;
if (cube != null) {
side = cube.getSide();
volume = cube.getvolume();
}
%>
<!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">
<body>
<h2>Cube Info Using JSP 2.0 </h2><br>
<b>Side of a Cube: ${cube.side} </b><br>
<b>Volume of a Cube: ${cube.getvolume()}</b><br>
<br></br><br>
Using Custom Tag:
<myjsp:displayform color="red"></myjsp:displayform>
<br></br><br>
<h2>Using JSTL:</h2>
<h2>Cube Info Using JSP 2.0 </h2><br>
<b>Side of a Cube: ${cube.side} </b><br>
<b>Volume of a Cube: <c:if test="${cube.volume}">10><font color="red"></font>the volume is ${cube.getvolume()}</c:if></b><br>
</body>
</html>
And in calcservlet:
package servlets;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class CalcServlet
*/
#WebServlet("/calc")
public class CalcServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/pages/result.jsp");
rd.forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String scube=request.getParameter("side");
Cube obj=new Cube();
try{
int cube=Integer.parseInt(scube);
obj.setSide(cube);
System.out.println("works");
obj.getvolume();
request.setAttribute("cube", obj);
}catch(NumberFormatException e){
}
RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/pages/result.jsp");
rd.forward(request, response);
}
}
In Cube:
package servlets;
public class Cube {
private int side;
public int getvolume() {
return side*side*side;
}
public int getSide() {
return side;
}
public void setSide(int side) {
this.side = side;
}
}
In form.jsp:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Form</title>
</head>
<body>
</head>
<body>
<h2>Side Form</h2> <!-- page heading -->
<form method=post action="calc"><!-- open a neew form -->
Side of a Cube: <input type=number name=side required><br> <!-- the iname parameter -->
<br></br>
<input type=submit value=Calculate><br> <!-- submit to the home page if everything is fine, else additem servlet and display the new item -->
<br><br><br></br>
</form> <!-- close form -->
</body>
</html>

Using objects in Session with Servlets and JSP

Could someone explain to me briefly how does passing an object and using it later in JSP.
I have this servlet, with the capability to make a new object and store it to session.
package application.servlets.test;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import application.data.character.House;
/**
*
* Servlet implementation class SessionTest
*/
#WebServlet("/persons")
public class SessionTest extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* #see HttpServlet#HttpServlet()
*/
public SessionTest() {
super();
// TODO Auto-generated constructor stub
}
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
/**
* #see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
House house = new House(34);
HttpSession session = request.getSession();
session.setAttribute("House", house);
request.getRequestDispatcher("test.jsp").forward(request, response);
}
}
This is the first JSP that forwards me to that servlet:
<html>
<body>
<h2>Hello World!</h2>
<form method="post" action="persons">
<input type="submit", value="Submit"/>
</form>
</body>
</html>
And Finally the servlet will forward me to this JSP. How do I now show it JSP getLevel() method. Or any method that would be in the object House? How do I print out the values?
<%# 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>
Hello this is just a test
<h1>Hello ${sessionScope.House}!!!</h1>
<% Object o = session.getAttribute("House");
%>
</body>
</html>
Just for in case this is my house class:
package application.data.character;
public class House {
private int level;
public House(int level) {
super();
this.level = level;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
}
you need to import the page in which your class is present
<%# page import="com.servlet.java.*"%>

neglect it--------------Sending an array to servlet from jsp page and recieving it in servlet------------ neglect it

*
neglect it
*
I am lerner in JSP and java field. I am stuck in a problem. I hv mentioned my code below.
My JSP code:
<%# 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>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(document).ready(function() {
$("#save").click( function ()
{
var arrayxx= new Array(5);
arrayxx[0]=0;
arrayxx[1]=3;
arrayxx[2]=4;
arrayxx[3]=9;
$.get('Save1',{arrayX:arrayxx},function(responseJson)
{
} );
});
});
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<input type="button" id="save" value="save" ></input>
</body>
</html>
My servlet:
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Save1 extends HttpServlet {
private static final long serialVersionUID = 1L;
public Save1() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("INSIDE SERVLET");
String [] yourList = request.getParameterValues("arrayX");
System.out.println(request.toString());
System.out.println(yourList[0]);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
I cant able to pass the array from JSP to servlrt.
Please help me with this. When i receive the array, i found that array does not contain any element.
Thanks in advance
As per your requirement I would suggest you to go for ajax like this way
$.ajax(
{
type: "POST",
url: "servlet", //Your full URL goes here
data: { parametername: parametervalue},
success: function(data, textStatus, jqXHR){
//alert(data);
}

How do I call an arrays methods from the JSP page in JSTL?

I stumbled upon servlets and I just love them compared to scriptlets since they perfectly divide logic and view. But I'm having trouble calling instance methods in my JSP page.
I have the following JSP page:
<%# 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>
<c:forEach items="${stringarray}">
${stringarray}
<br/>
</c:forEach>
</body>
</html>
And the following Servlet:
package controller;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class Servlet
*/
#WebServlet("/Servlet")
public class Servlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public Servlet()
{
// TODO Auto-generated constructor stub
}
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String[] strarray = new String[5];
strarray[0] = "zero";
strarray[1] = "one";
strarray[2] = "two";
strarray[3] = "three";
strarray[4] = "four";
request.setAttribute("stringarray", strarray);
request.getRequestDispatcher("index.jsp").forward(request, response);
}
/**
* #see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// TODO Auto-generated method stub
}
}
Why can't I call the arrays methods with the dot separator in my JSP page?!
I think what you're looking for is the following:
<c:forEach var="stringElement" items="${stringarray}">
${stringElement}
<br/>
</c:forEach>
The c:forEach tag loops over each element in the ${stringarray}, but to access each item, you have to define a variable. See also the TLD docs

Categories

Resources