JSP

JavaServer Pages (JSP) allow the development of dynamically generated web pages. It uses the Java programming language; JSP pages are translated into servlets at runtime, with each servlet being cached and reused until the JSP is modified. JSP allows Java code to be interleaved with static web markup content, so the resulting page can be compiled and executed on the server to deliver the content.

Share tech news, updates, or what's on your mind.

Sign up to Post

 

 
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
 
public class MyHashMapEntrySet3 {
 
    public static void main(String arg[]){
      HashMap hm = new HashMap<Integer, String>();
    	//HashMap hm = new TreeMap<String, String>();
    	//HashMap hm = new LinkedHashMap<String, String>();
        //add key-value pair to hashmap
        hm.put(3, "C");
        hm.put(1, "A");
        hm.put(2, "B");
        //hm.put(3, "C");
        System.out.println(hm);
        //getting value for the given key from hashmap
       /* Set<Entry<String, String>> entires = hm.entrySet();
        for(Entry<String,String> ent:entires){
            System.out.println(ent.getKey()+" ==> "+ent.getValue());*/
       //d }
    }
}

Open in new window


{1=A, 2=B, 3=C}


i wonder how i got above sorted output based on key all the time first 1 then 2 then 3 key set? please advise
0
i have tried  to return a Boolean to the method  isEdit()  but with no  success......can anyone please point me to the right direction? The IDE give me error saying can not return a value from method with void type,i don't see any void in my method..i have returned Boolean.

// create an empty array list with an initial capacity
	List<Integer> companyID = new ArrayList<Integer>(4);
	companyID.add(254162);
	companyID.add(272836);
	companyID.add(285582);
	companyID.add(279944);

	public boolean isEdit(){

		if (companyID.contains(company.getId()) ) {

			return acl.hasPermission("Companies Edit");
		} else {
			return false;
		}
	}

Open in new window

0
Hi,

I have a html to logn and then jsp to insert to mysql databse.

i am getting errors like below

java.sql.SQLException: Incorrect date value: 'null' for column 'dob' at row 1

java.sql.SQLException: Column 'userid' not found.

java.sql.SQLException: Unknown column 'typeofaccout' in 'field list'

java.sql.SQLException: Column 'userid' not found.


how to effectively debug and resolve these kind of jsp and html related issues.

can i put debug point in jsp page and html page like regular java file and start application in debug mode?
please advise.
0
my web.xml file is
<?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://" version="3.0">
 <servlet>
        <servlet-name>CreationClient</servlet-name>
        <servlet-class>com.sdzee.tp.servlets.CreationClient</servlet-class>
    </servlet>
    <servlet>
        <servlet-name>CreationCommande</servlet-name>
        <servlet-class>com.sdzee.tp.servlets.CreationCommande</servlet-class>
    </servlet>
     
    <servlet-mapping>
        <servlet-name>CreationClient</servlet-name>
        <url-pattern>/creationClient</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>CreationCommande</servlet-name>
        <url-pattern>/creationCommande</url-pattern>
    </servlet-mapping>

</web-app>

i try to execute a jsp file creerClient.jsp in my web-inf directory and i get the error

type Rapport d''état

message

description La ressource demandée n''est pas disponible.

someone can help me ?
thanks
0
Hi,

Eclipise maven project when i right click and say Maven and I see option" disable/enable workspace resolution" option is there. what is the use of that option and when i supposed to select that. please advise
0
Hi,

When i go to below url
http://localhost:65535/JSPFinalWebProject/authorize.jsp
it is being redirected to wrong url
http://localhost:65535/JSPFinalWebProject/index.jsp
with below error
HTTP Status 404 - /JSPFinalWebProject/index.jsp


type Status report

message /JSPFinalWebProject/index.jsp

description The requested resource is not available.


Apache Tomcat/9.0.0.M15

please advise on how to fix. Not sure hpw and why index.jsp coming to picture. please advise
0
Hi

In my jsp application i am getting below error

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO)

how to resolve this. please advise
0
Hi,

i am trying to run below example by instlling mysql database

http://www.roseindia.net/jsp/prepared-statement-query.shtml

i am getting attached error



HTTP Status 500 - An exception occurred processing JSP page /InsertJSPPreparedStmt.jsp at line 84


type Exception report

message An exception occurred processing JSP page /InsertJSPPreparedStmt.jsp at line 84

description The server encountered an internal error that prevented it from fulfilling this request.

exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /InsertJSPPreparedStmt.jsp at line 84

81:                }
82:             finally {
83:                 // close all the connections.
84:                 pstatement.close();
85:                 connection.close();
86:             }
87:         }


Stacktrace:
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:588)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:481)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)


root cause
java.lang.NullPointerException
      org.apache.jsp.InsertJSPPreparedStmt_jsp._jspService(InsertJSPPreparedStmt_jsp.java:198)
      
0
Hi,

I am following below example

http://www.roseindia.net/jsp/prepared-statement-query.shtml

account2.jsp is
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd" > 
      <%@ page import="java.sql.*" %> 
<%@ page import="java.io.*" %> 
<HTML>
<HEAD>
  <TITLE>insert data using prepared statement </TITLE>
</HEAD>
    <BODY bgcolor="#ffffcc">
  <font size="+3" color="green"><br>Welcome in www.roseindia.net !</font>
  <FORM action="account2.jsp" method="get">
    <TABLE style="background-color: #ECE5B6;" WIDTH="30%" >
         <TR>
	      <TH width="50%">Name</TH>
		  <TD width="50%"><INPUT TYPE="text" NAME="name"></TD>
	  </tr>
      <TR>
	     <TH width="50%">City</TH>
		 <TD width="50%"><INPUT TYPE="text" NAME="city"></TD>
	  </tr>
	  <TR>
	     <TH width="50%">Phone</TH>
		 <TD width="50%"><INPUT TYPE="text" NAME="phone"></TD>
	  </tr>
	  	  <TR>
	      <TH></TH>
		  <TD width="50%"><INPUT TYPE="submit" VALUE="submit"></TD>
	  </tr>
   </TABLE>
<%


/* String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:XE";
String username = "sample";
String password = "admin";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
String dob=request.getParameter("username");
String name=request.getParameter("password");
String address=request.getParameter("username");
String email=request.getParameter("password");
String 

Open in new window

0
Hi,

i wonder what are differences between sorce folder and folder in eclipse. When to use which one. please advise
0
How  can I  resolve   HTTP status 404?I am a newbie JEE... I have tried to search over internet with no success. This is  a spring project imported in  Eclipse. I did import and rebuilt project...with no errors and then deploy in my server.But when I   right  click my  deloyed project and then click   open home page,pa2.png

I do  get  below  HTTP Status 404 error. I think I am missing something has to do with configuration

pag1.png
0
Hi,

As attached my wildfly for is at 8180 i think. How to validae if it 8180 or not?


when i run ejb example i get below error



javax.naming.NoInitialContextException: Cannot instantiate class: org.jboss.naming.remote.client.InitialContextFactory [Root exception is java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory]
      at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
      at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
      at javax.naming.InitialContext.init(Unknown Source)
      at javax.naming.InitialContext.<init>(Unknown Source)
      at co.assignment15.Module15Client.main(Module15Client.java:51)
Caused by: java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory
      at java.net.URLClassLoader.findClass(Unknown Source)

i just ran one simple jsp project and got attached output at
http://localhost:8180/TestJSPProjectWildFly/NewFile.jsp

i forgot the password for server as i gave username as admin .

any way i can retrieve password?
do i need password in future?
please advise
wildfly.png
wfjsp.png
0
Hi,

my code is
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
	<h1>Login Page</h1>
	<center>
		<h2>Signup Details</h2>
		<form action="LoginCheck.jsp" method="post">
			<br />Username:<input type="text" name="username"> <br />Password:<input
				type="password" name="password"> <br />
			<input type="submit" value="Submit">
		</form>
	</center>
</body>
</html>

Open in new window

LoginCheck.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
	<%
	
	String driver = "oracle.jdbc.driver.OracleDriver";
	String url = "jdbc:oracle:thin:@localhost:1521:XE";
	String username = "sample";
	String password = "admin";
	Class.forName(driver);
	Connection conn = DriverManager.getConnection(url, username, password);
	


	String name=request.getParameter("username");
    String pwd=request.getParameter("password");
    
 
    //Statement st=conn.createStatement();
	
    
	String str_qry = "select * from user_pass where user_id='"+name + "' AND password='"+pwd + "'";
	System.out.println("Given query is : " + str_qry);
	ResultSet rst=st.executeQuery(str_qry);
	
	
	
	if (!rst.next())
	{
		%>
		<h1> Invalid user </h1>
	<% }
	else { %>
		<h1> valid user </h1>
	<%   }
	conn.close();
	System.out.println("Connection closed...");
	%>
</body>
</html>

Open in new window


i want t check the table and if pass it should go to next page called menu.jsp where i have 5 links.

but i am seeing folowing errors in LoginCheck.jsp page


Multiple annotations found at this line:
      - Connection cannot be resolved
       to a type
      - DriverManager cannot be
       resolved


Multiple annotations found at this line:
      - ResultSet cannot be resolved
       to a type
      - st cannot be resolved


please advise on how to resolve
0
Hi,

I am working on below example

http://mrbool.com/how-to-create-a-login-form-with-jsp/25685
my login.html is
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
	<h1>Login Page</h1>
	<center>
		<h2>Signup Details</h2>
		<form action="LoginCheck.jsp" method="post">
			<br />Username:<input type="text" name="username"> <br />Password:<input
				type="password" name="password"> <br />
			<input type="submit" value="Submit">
		</form>
	</center>
</body>
</html>

Open in new window


my LoginCheck.jsp is
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
	<%
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		if ((username.equals("anurag") && password.equals("jain"))) {
			session.setAttribute("username", username);
			response.sendRedirect("Home.jsp");
		} else
			response.sendRedirect("Error.jsp");
	%>
</body>
</html>

Open in new window


i ran application and entered anurag and jain as username and password within login.html
i expected to go to LoginCheck.jsp but getting below error

http://localhost:9999/FinalWeb/Home.jsp
please advise

HTTP Status 404 - /FinalWeb/Home.jsp


type Status report

message /FinalWeb/Home.jsp

description The requested resource is not available.


Apache Tomcat/7.0.47

not sure where Home.jsp came in picture??

my intention is once login successful come to a page with 4 different links like menu.
one link says create account
second link say perform credit operatin
then show like receipt etc
0
Hi,

public class Exceptions {

	public void test() throws NullPointerException {
		NullPointerException e = new NullPointerException("");
		throw e;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		// int arr[] = { 1, 2, 3, 4, 5 };

		try {
			// System.out.println(arr[5]);
			//System.out.println("next");
			// } catch (NullPointerException e) {
			//Exceptions obj = new Exceptions();
			//obj.test();
			int a=5;
			int b=0;
			int c=a/b;

		}
		// System.out.println("in between try and catch");
		// catch (ArrayIndexOutOfBoundsException e) {
		// catch (NullPointerException e) {
		catch (Exception e) {
			// TODO: handle exception
			System.out.println(e.getMessage());
		}
		// System.out.println("hi");
	}

}

Open in new window


i see above code generating
/ by zero


i wonder where above message came from as i have not set any message in my code?
0
Hi,

public class Exceptions {

	public void test() throws NullPointerException {
		NullPointerException e = new NullPointerException("");
		throw e;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		// int arr[] = { 1, 2, 3, 4, 5 };

		try {
			// System.out.println(arr[5]);
			//System.out.println("next");
			// } catch (NullPointerException e) {
			Exceptions obj = new Exceptions();
			obj.test();

		}
		// System.out.println("in between try and catch");
		// catch (ArrayIndexOutOfBoundsException e) {
		// catch (NullPointerException e) {
		catch (Exception e) {
			// TODO: handle exception
			System.out.println(e.getMessage());
		}
		// System.out.println("hi");
	}

}

Open in new window


why above program generates null output or no output.

please advise
0
public class Exceptions {

	public void test() throws Exception{
		NullPointerException e=new NullPointerException("exception occured");
		throw e;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//int arr[] = { 1, 2, 3, 4, 5 };

		try {
			// System.out.println(arr[5]);
			System.out.println("next");
			// } catch (NullPointerException e) {
			Exceptions obj=new Exceptions();
			obj.test();

		}
		// System.out.println("in between try and catch");
		// catch (ArrayIndexOutOfBoundsException e) {
		catch (NullPointerException e) {
			// TODO: handle exception
			System.out.println(e.getMessage());
		}
		// System.out.println("hi");
	}

}

Open in new window


why above code generates
Unhandled exception type Exception

i thought NullPointerException is sub class of Exception so it is ok here to catch NPE instead of exception? please advise
0
Hi,

public class Exceptions {

	public void test() throws NullPointerException{
		Exception e=new Exception("exception occured");
		throw e;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int arr[] = { 1, 2, 3, 4, 5 };

		try {
			// System.out.println(arr[5]);
			System.out.println("next");
			// } catch (NullPointerException e) {

		}
		// System.out.println("in between try and catch");
		// catch (ArrayIndexOutOfBoundsException e) {
		catch (Exception e) {
			// TODO: handle exception
			System.out.println(e.getMessage());
		}
		// System.out.println("hi");
	}

}

Open in new window


why above code giving compile time error saying

Unhandled exception type Exception


please advise

is catch has to match the test() throws exception type or other way. What is best practice. please advise
0
Hi,

public class Exception {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
int arr[]={1,2,3,4,5};

try {
	System.out.println(arr[5]);
	System.out.println("next");
//} catch (NullPointerException e) {
} catch (ArrayIndexOutOfBoundsException e) {
	// TODO: handle exception
	System.out.println("exception");
}
System.out.println("hi");
	}

}

Open in new window


exception
hi


above is more graceful exit
public class Exception {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
int arr[]={1,2,3,4,5};

try {
	System.out.println(arr[5]);
	System.out.println("next");
} catch (NullPointerException e) {
//} catch (ArrayIndexOutOfBoundsException e) {
	// TODO: handle exception
	System.out.println("exception");
}
System.out.println("hi");
	}

}

Open in new window

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
      at Exception.main(Exception.java:9)


below is abrupt exit at run time so these are called RuntimeExceptions like ArrayIndexOutOfBoundsException etc.

There is no other converse term like compile time exceptions right. How to replicate compile time exception with a example?
0
Hi,

to run servlets and JSPs(assuming they do some CRUD operations on oracle database), JDBC java programs etc do i need to set ojdbc5.jar both to eclipse build path and also to tomcat lib directory?

how eclipse build path different from web container like tomcat lib directory?

(like C:\Program Files\Apache Software Foundation\Tomcat 9.0\lib)
when i set to eclipse build path where does that jar go and sit? which location?

Servlet jar on the contrary we only set at eclipse build path only as that is already present in tomcat lib directory?


please advise
0
Hi,

package com.gale.domain;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.Map.Entry;

import java.util.Set;

public class HashTableExBridged {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Employee e1 = new Employee(1, "sam", 90);
		Employee e2 = new Employee(2, "mark", 91);
		Employee e3 = new Employee(3, "lara", 92);
		Employee e4 = new Employee(4, "alex", 93);
		Employee e5 = new Employee(5, "bk", 94);

		Hashtable<Integer, Employee> m = new Hashtable();
		m.put(1, e1);
		m.put(2, e2);
		m.put(3, e3);
		m.put(4, e4);
		m.put(5, e5);

		System.out.println(m);

		/*Set<Entry<Integer, Employee>> s = m.entrySet();

		for (Entry<Integer, Employee> x : s) {
			System.out.println("key is-->" + x.getKey());
			System.out.println("name is-->" + x.getValue().name);
			System.out.println("marks are==>" + x.getValue().mark);
		}*/

		/*
		 * Enumeration n = m.keys();
		 * 
		 * int id, big = 0, bigId = 0; while (n.hasMoreElements()) { id = (int)
		 * n.nextElement();
		 * 
		 * Employee emp = m.get(id); if (big < emp.mark) { big = emp.mark; bigId
		 * = id; } }
		 */
		int bigMark = 0, bigIdOfPerson = 0;
		// for(Map.Entry<Integer, Employee> x:m) {
		for (Map.Entry<Integer, Employee> x : m.entrySet()) {
			Employee emp = x.getValue();
			if (bigMark < emp.mark) {
				bigMark = emp.mark;
				bigIdOfPerson = x.getKey();
			}

		}

		Employee employeeHighestMarks =

Open in new window

0
Hello,
I would like to know which front-end technology i need to use to
have a result like the picture attached.
All is drag and dropable and working on a browser.

Regards,sample
0
Hi,

i created Sample servlet at

C:\gpSoftwares\apache-tomcat-9.0.0.M17-windows-x64\apache-tomcat-9.0.0.M17\webapps\gpProjects\WEB-INF\classes

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWorld extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
    {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Hello World!!!!</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Hello World!</h1>");
        out.println("</body>");
        out.println("</html>");
    }
}

Open in new window


i created basically
WEB-INF under gpProjects

under WEB_INF i created classes under which i created above Sample.java servlet
under WEB_INF i wrote web,xml as
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:web="http://xmlns.jcp.org/xml/ns/javaee">
  <servlet>
    <servlet-name>sample</servlet-name>
    <servlet-class>Sample</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>sample</servlet-name>
    <url-pattern>/sample</url-pattern>
  </servlet-mapping>  
</web-app>

Open in new window


i went to coomand prompt and tried to compile
i got below 7 errors

0
function editInvestor(investorId, companyId) {
		var contactId = showModalDialog('add_company_contact_modal_wrap.jsp?single=true&companyIds=' + companyId, '', 'dialogWidth:800px;dialogHeight:600px;resizable:yes;');
		if (contactId) {
			$('#investors').load('/company_add.jsp #investorCoolGrid', {
				'id': <%=company.getId()%>,
				'action':'updateInvestor',
				'investorId':investorId,
				'investorContactId':contactId,
				'type':'investors'
			}, function() {
				$.gritter.add({
					title: "Status Updated",
					text: "Investor Status has been updated",
					class_name: "gritter-info"
				});
			});
		}
	}

Open in new window


I am  javascript newbie.Can anyone please tell me why  #investorCoolGrid  ID is not available in /company_add.jsp and yet the edit function works just fine.My understanding  from  Jquery Doc is :-

When this method executes, it retrieves the content of /company_add.jsp, but then jQuery parses the returned document to find the element with an ID of investorCoolGrid  . This element, along with its contents, is inserted into the element with an ID of investors, and the rest of the retrieved document is discarded.
0
Hi,

I installed tomcat 8.5 from winodws installer to
c:/Tomcat8


I went from command prompt to below path
C:/Tomcat8/bin and then gave command tomcat8

i see below error



18-Jan-2017 22:19:29.627 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.5.11
18-Jan-2017 22:19:29.632 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Jan 10 2017 21:02:52 UTC
18-Jan-2017 22:19:29.632 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.5.11.0
18-Jan-2017 22:19:29.633 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Windows 10
18-Jan-2017 22:19:29.633 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            10.0
18-Jan-2017 22:19:29.633 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
18-Jan-2017 22:19:29.633 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             C:\Program Files\Java\jre1.8.0_102
18-Jan-2017 22:19:29.633 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_102-b14
18-Jan-2017 22:19:29.633 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
18-Jan-2017 22:19:29.634 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         C:\Tomcat 8.5
0

JSP

JavaServer Pages (JSP) allow the development of dynamically generated web pages. It uses the Java programming language; JSP pages are translated into servlets at runtime, with each servlet being cached and reused until the JSP is modified. JSP allows Java code to be interleaved with static web markup content, so the resulting page can be compiled and executed on the server to deliver the content.

Top Experts In
JSP
<
Monthly
>

No Top Experts for this time period. Answer questions to earn the title!