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

Can  anyone please tell me why my callDurationId is  null?I can see the value has been passed from the front end but on the backend I see it null.That caused my table not to be updated.

picture1.png
0
I like learning object oriented php

but do not want to be bogged down by html, css, jquery, javascript, ajax

I know I can use command line php but if a client is paying me; client usually wants artwork.
A css designer will draw a picture of an expected form and I am forced CODE the html and css to the exact layout of the picture

then the client states the the textbox is 1 inch (.5 cm) too tall.



do other object oriented languages force me to learn so much design software


Please add many other object oriented programming zones
0
out.println("<form  name="form" action="post" onsubmit="return validate();">");
                  out.println(Enter User Id:);
                  out.println("<input type="text" name="userId" >");
                  out.println("</form>");

                        how can I use the above code inside jsp tags.
0
What is the difference between screen1 login.html(under TestFilter project) and screen2 login.html(uder Mod project)

http://localhost:65535/Mod/login.html opens login page nicely with username and password


where as below

http://localhost:65535/TestFilter/login.html

gives error as



HTTP Status 404 - /TestFilter/login.html


type Status report

message /TestFilter/login.html

description The requested resource is not available.


Apache Tomcat/9.0.0.M15

 To my eyes both login.html files are almost same location under WebContent outside WEB_INF
when i try to move login.html into WEBCONTENT similar to other prject as attached it says conflict with name and renames as index2.htlm or login2.html etc.
Please advise
screen1.png
screen2.png
screenMove.png
screenMoveConflict.png
0
I have  tried  to   check online with no success.Can anyone point me to the right direction please?The error came after I added one get method at the end of the method below i.e
testNullOrZero(activity.getActivityCallDurationId()),

Open in new window


public static void updateActivity(Activity activity, Integer userId) {
		try {
			Object[] outs = charmCall("{ call CRM.activity_maint_pkg.update_activity (?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?) }",
					new Object[] {
							userId,
							testNullOrZero(activity.getId()),
							activity.getActivityTypeId(),
							testNull(activity.getSubject()),
							testNull(activity.getCorpFincFlag()),
							testNull(getTimestamp(activity.getTodoPlanStartDate())),
							testNull(activity.getConfidentialFlag()),
							testNull(activity.getBestActionFlag()),
							testNull(getTimestamp(activity.getActivityStartDate())),
							testNull(getTimestamp(activity.getActivityEndDate())),
							testNull(activity.getCalledFromNum()),
							testNull(activity.getCalledNum()),
							testNull(activity.getCallerTypeCode()),
							testNull(activity.getCallerDisplayFlag()),
							testNull(activity.getComments()),
							testNull(activity.getTickers()),
							testNull(activity.getContactIds()),
							testNull(activity.getTwpAttendeeIds()),
							testNull(activity.getDepartmentId()),
							testNull(getTimestamp(activity.getFollowUpDate())),
							testNull(activity.getFollowUpUserIds()),
							

Open in new window

0
Hi,

/i am working on jsp simple application to connect to orace database to validate usernae and password.

i get below error


java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
      org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1275)
      org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1109)
      org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:123)
      org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:60)
      java.lang.Class.forName0(Native Method)
      java.lang.Class.forName(Unknown Source)
      org.apache.jsp.login_jsp._jspService(login_jsp.java:138)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
      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)


i have added ojdbc6.jar in build path though. Not sure why still getting above error

my jsp code which comes from login.html.

code is

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
	org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1275)
	

Open in new window

0
Hi,

I am trying login html which leads to jsp page where it validates username and password. If it is correct should display valid user in jsp otherwise redirect to same login html similar to below

http://www.codemiles.com/jsp-examples/login-using-jsp-t3417.html

my code is
<form action="servlet1">  
Name:<input type="text" name="name"/><br/>  
Password:<input type="password" name="password"/><br/>  
  
<input type="submit" value="login">  
  
</form>  

Open in new window


<%@ 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>
<%
            String username = request.getParameter("username");
            String password = request.getParameter("password");
           out.println("Checking login<br>");
            if (username == null || password == null) {
 
                out.print("Invalid paramters ");
            }
 
            // Here you put the check on the username and password
            if (username.toLowerCase().trim().equals("admin") && password.toLowerCase().trim().equals("admin")) {
                out.println("Welcome " + username + " <a href=\"index.jsp\">Back to main</a>");
                session.setAttribute("username", username);
            }
           else 
    

Open in new window

0
Hi,

I have an old JSP project in which the request is sent like this

http://myhost:8080/myjava/WBCM?triggername=sysmgrtest&cmd=mstrsysmgr&cmddelay=0&projname=

and is handled in the code at the end

This kind of URL is shared with many existing users. Now I need to add a new request parameter inpfilename

http://myhost:8080/myjava/myjsp?triggername=alpha&cmd=beta&cmddelay=0&projname=omega&inpfilename=abcdefg

but i need to make inpfilename as optional request parameter or else all the old URLs (100s of them) will have to be modified which is not possible

How can I do that ? in the following code to ensure that I can keep adding new request parameters but the OLD URLs don't break

thanks
-anshu


public static void handleRequest(HttpServletRequest req, HttpServletResponse res) throws IOException {

            //out = res.getWriter();
            //res.setContentType("text/plain");

            
            
            String paramName="";
            
            
            paramName = "cmd";
            commandType = req.getParameter(paramName);
            
            paramName = "triggername";
            triggerName = req.getParameter(paramName);
            
        paramName="cmddelay";
        commandDelay=Integer.parseInt(req.getParameter(paramName));
            
        paramName = "projname";
        projectName = req.getParameter(paramName);
       
       
            
      }
0
Hi - I want to read and write a CSV File thru HTML or Java script or Perl or Jquery.
What is the best way to do it.

I want to read the csv file and should be able to edit a value and save it or add a new line to the csv.
Sample CSV:
1,2,3
2,3,4
3,4,5

I should be able to edit any value in the csv thru html.
how can I accomplish that.

Thanks
0
Hi,

I am working on below code
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class FirstSwap {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		// String[] myFirstStringArray = new String[]{"String 1", "String 2", "String 3"};
		String[] st=new String[]{"ab","ac"};
		System.out.println("hi output is---->"+(Arrays.toString(firstSwap(st))));
		
	/*	 //Prior to Java 8
	    System.out.println(Arrays.toString(intArray));
	    System.out.println(Arrays.toString(strArray));

	    // In Java 8 we have lambda expressions
	    Arrays.stream(intArray).forEach(System.out::println);*/

	}
	public static String[] firstSwap(String[] strings) {
		   
		  Map<String, Integer> map = new HashMap<String, Integer>();
		  
		    Set<Entry<String, Integer>> set = map.entrySet();
		      Iterator<Entry<String, Integer>> iterator = set.iterator();
		      while(iterator.hasNext()) {
		         Map.Entry mentry = (Map.Entry)iterator.next();
		         System.out.print("key is: "+ mentry.getKey() + " & Value is: ");
		         System.out.println(mentry.getValue());
		      }
		     
		  for (int i = 0; i < strings.length; i++) {
		     
		    String key = String.valueOf(strings[i].charAt(0));
		     
		    if (map.containsKey(key)) {
		       
		      int val = map.get(key);
		      if (val == -1) {
		        continue;
		      }
		       
		      // 

Open in new window

0
Hi,,
why HTTPSessionBindingListernter  is  not need configured in deployment descriptor in case of servlet listener.

HTTPSessionBindingListernter different from HTTPSessionAttributeListernter. HTTPSessionActivationListernters.  please advise
0
I  have tried  to ajax  using  post  to  jsp  script my  html table rows for weeks now with no success.Can anyone please  guide me on this?Below is  what I have done so far.


window.addEventListener("DOMContentLoaded", function () {

			var form = document.getElementById("updateDealPmtForm");

			document.getElementById("btn").addEventListener("click", function () {


				$('#notSoCoolGrid > tr').each(function(event) {

					event.preventDefault();

					var postData = {
						paymentId:$('#paymentId').text(),
						id:$('#deald').text(),
						pType:$('#pType').text(),
						pAmt:$('#pAmt').text(),
						currency:$('#currency').text(),
						pInvDate:$('#pInvDate').text(),
						pRecDate:$('#pRecDate').text(),
						comments:$('#comments').text()
					};
					console.log(postData);
					$.ajax({
						async: false,
						type: "POST",
						cache: false,
						url: "/update_deal_pmt_script.jsp",
						data: postData.$('input, select').serialize() ,
						success: function(msg){
							alert("submitted");
						}

					});
				});


			});

		});

Open in new window

0
Hi,

How thymeleaf natural templating vs JSP are different. what are advantages and disadvantage, practical uses of thymeleaf compared to JSP for creating web applications. please advise
0
Hii have the following code. i had 2 options with me, either i run the java code to convert into ColdFusion or create the java code as jsp and run it thru cfhttp by passing required parameters and accessing thm.

but probem is i do not know either way what to do and where to start

can someone guide me please

if i do call cfhttp, how do i pass and how do i call from that jsp page


long nonce = Math.abs(SecureRandom.getInstance("SHA1PRNG").nextLong());
            returnMap.put(APIResourceConstants.SecurityConstants.NONCE, Long.toString(nonce));
            returnMap.put(APIResourceConstants.SecurityConstants.APIKEY, requestOptions.getApiKey());
            returnMap.put(APIResourceConstants.SecurityConstants.TIMESTAMP, Long.toString(System.currentTimeMillis()));
            returnMap.put(APIResourceConstants.SecurityConstants.TOKEN, requestOptions.getToken());
            returnMap.put(APIResourceConstants.SecurityConstants.APISECRET, requestOptions.getSecret());
            returnMap.put(APIResourceConstants.SecurityConstants.PAYLOAD, payLoad);

this is the parameters and this is how the data is generated !!!!!!!!!!!!!!!!

Mac mac=Mac.getInstance("HmacSHA256");
        String apiSecret= data.get(APIResourceConstants.SecurityConstants.APISECRET);
        SecretKeySpec secret_key = new SecretKeySpec(apiSecret.getBytes(), "HmacSHA256");
        mac.init(secret_key);
        String apikey = data.get(APIResourceConstants.SecurityConstants.APIKEY);
        

Open in new window

0
We are using JavaScript environment inside of another product.

I would like some code that would list all of the functions that are available ?

Its simple to interrogate an object for all of its methods and properties.
But how do we list all the possible top level objects/Methods/Properties that java and/or the vendor may have exposed ?

Thanks
0
Hi,
Could you suggest where I can browse/buy latest website templates. I prefer HTML5 based templates

I'm checking this
http://www.templatemonster.com/

Thanks in advance.
0
I have to learn JAVA,

Which book would get me started.

I had some class room lessons about 5 years ago.

And that is the only background i have

Toni
0
Hi I am using jquery hemiintro i want to hide intro in after page second time refersh
0
I have HTML/JSP form in one Java EE application. There are numerous fields and one of them is text area. That text area is of type "text" and is supposed to accept  numeric (integer) values separated by colon (some Control IDs).

Before sending it to servlet and other java classes for further processing I would like to validate input on client side i.e. in browser.

What would be best way to check if input is valid i.e. 100, 200, 300, 400, 500 is valid but for 100, 200, someText, 400, 500 I would show alert with warning that input doesn't contain integer numbers only?
0
Hi,

Why we use instanceof  operator in java in down casting only not in upcasting. How ClassCastException  are generated?
please advise
0
Here is code which should work (part of main page which takes care about login, I know this shouldn't be done from JSP/JSTL this is just one example from book I am reading):

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>

<sql:query var="result">
  select * from users where user=? and password=?
  <sql:param value="${param.user}" />
  <sql:param value="${param.pw}" />
</sql:query>

<c:choose>
  <c:when test="${result.rowCount > 0}">
    <c:set var="user" scope="session" value="${param.user}" />
    <c:set var="rss" scope="session" value="${result.rows[0].RSS}" />
  </c:when>
  <c:otherwise>
    <c:set var="failedLogin" scope="request" value="true"/>
	<c:set var="user" value="${result.rows[0].user}" />
	<c:set var="pw" value="${result.rows[0].pw}" />
	<c:set var="rowCount" value="${result.rowCount}" />
	<c:set var="resultSQL" value="${result}" />
	<jsp:forward page="failed.jsp"  />
  </c:otherwise>
</c:choose>
<jsp:forward page="dynamicPortal.jsp" />

Open in new window



Quick check in DB (hsqldb) shows that there is indeed one user properly populated with username and password and RSS i.e. result.rowCount should be greater than zero, but it isn't.

I added   <c:otherwise> option when trying to debug what's wrong.

What could be wrong here?
0
Hi,

I am learning javascript, trying out the below code, it is not working.
Just wanted to check if the below is feasible.

<html>
<script type = 'text/javascript'>
function call1()
{
this.c = 10;
document.write("call done");
}
function call2()
{
cta = new call1();
//document.write("call2"+cta.c);
}
function execute(){
var abc = new call2();
document.write(abc.cta.c); // can I do like this. if this is wrong any other way.

}
</script>
<body>
<input type = button onclick = "execute()"/>
</body>
</html>
--------------------------------------------
I have created a function "call1". This has a variable "C".
, and created an object for it in another function "call2"
then created a function "execute" to create an object for "call2"
now wanted to access the variable "C" in "call1" through "call2"

Is it possible to do like that?
0
I am reading some tutorials and in one of them there is code how to use JSP to connect to DB directly (I know it's bad practice even tutorials mention it). Code works, but what puzzles me is WHERE does it store newly created table "COUNTER"?
There was no special setup for HSQLDB - I've just downloaded it, unpacked it and run runServer.bat
which has in it:
cd ..\data
@java -classpath ../lib/hsqldb.jar org.hsqldb.server.Server %1 %2 %3 %4 %5 %6 %7 %8 %9

Open in new window

Then CMD message informed me that server is up and running:
C:\hsqldb\bin>cd ..\data
[Server@4517d9a3]: [Thread[main,5,main]]: checkRunning(false) entered
[Server@4517d9a3]: [Thread[main,5,main]]: checkRunning(false) exited
[Server@4517d9a3]: Startup sequence initiated from main() method
[Server@4517d9a3]: Could not load properties from file
[Server@4517d9a3]: Using cli/default properties only
[Server@4517d9a3]: Initiating startup sequence...
[Server@4517d9a3]: Server socket opened successfully in 6 ms.
[Server@4517d9a3]: Database [index=0, id=0, db=file:test, alias=] opened successfully in 261 ms.
[Server@4517d9a3]: Startup sequence completed in 269 ms.
[Server@4517d9a3]: 2016-07-31 13:32:02.444 HSQLDB server 2.3.4 is online on port 9001
[Server@4517d9a3]: To close normally, connect and execute SHUTDOWN SQL
[Server@4517d9a3]: From command line, use [Ctrl]+[C] to abort abruptly

Open in new window


Then I executed JSP code:
<%--
  Run this file before using the other JSP pages in this directory to
  set up your database tables.
--%>

<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>

<%-- Sets up 'counter' table --%>
<sql:update>
  create table counter (
    counter integer
  )
</sql:update>
<sql:update>
  insert into counter(counter) values(0)
</sql:update>

Open in new window


and another JSP page reads from DB:
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>

<sql:transaction>

  <sql:update>
    update counter set counter = counter + 1
  </sql:update>
  <sql:query var="result">
    select * from counter
  </sql:query>
  <c:set var="count" value="${result.rows[0].counter}" />

</sql:transaction>

<%-- Display the count --%>
Number of visitors to this page:  <c:out value="${count}"/>

Open in new window


But when I try to find table COUNTER there is no that table?
Not in INFORMATION_SCHEMA, not in PUBLIC, not in SYSTEM_LOBS?
Where could it go?
Screen-Shot-07-31-16-at-01.45-PM.PNG
0
I get error: ..useBean: Duplicate bean name: {0}..
for this tag
<jsp:useBean id="abc" class="java.util.HashMap" scope="request" />

the id="abc" is only once in the whole jsp page.
1
Does anyone have a straightforward example for implementing drag-and-drop to a webpage? I am using Firefox (though I hope that doesn't matter) and jsp. I want to drag an image from a Windows Explorer view to a spot on a web page. I don't really need the image to show on the webpage immediately, but I would like to be able to save the image to disk on the server. In other words, have it kind of act like a photo filing app. I do this all the time to websites, but don't know how to do it myself on my website. For example, I've dragged images to an "ico maker" website, just as I've described.

How do I do this?
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!