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

I'm very confused. I've been programming with Apache/Tomcat for about 9 years, and I'm stumped on something likely very simple. I have the following file, $CATALINA_HOME/webapps/myapp/testme.html:
<!DOCTYPE HTML>
<html>
<body>
hello
<img alt="" src="content/sidebar/OhioRoyalArch.gif"/>
</body>
</html>

Open in new window

When I load the html in a browser, the "hello" shows, but not the image. the apache access log gives me

"GET /content/sidebar/OhioRoyalArch.gif HTTP/1.1" 404

The permissions appear OK:
$ ls -la content/sidebar/
total 132
drwxrws--- 2 mfoley horeb  4096 2016-05-21 13:56 ./
drwxrws--- 4 mfoley horeb  4096 2016-05-21 13:43 ../
-rwxrwx--- 1 mfoley horeb 30913 2016-05-21 13:56 OhioRoyalArch.gif

Open in new window

The tomcat user.group is tomcat.tomcat and is a member of group horeb:

/etc/group
horeb:x:1000:tomcat,mfoley,daemon

In fact, all files in the app directory belong to group horeb. I have no trouble access files in the images directory:
$ ls -l images
total 684
-rwxr----- 1 mfoley horeb  98737 2016-04-30 01:06 ark2.jpg*
-rw-rw---- 1 mfoley horeb  32533 2016-05-05 11:36 circleTriangleBadge.gif
-rw-rw---- 1 mfoley horeb 524657 2016-05-05 23:35 eyeballLongOnce.gif
-rw-rw---- 1 mfoley horeb  25471 2016-05-14 22:38 facebook.jpg

Open in new window

"GET /content/sidebar/OhioRoyalArch.gif HTTP/1.1" 404 1060
"GET /images/circleTriangleBadge.gif HTTP/1.1" 304 -
"GET /images/ark2.jpg HTTP/1.1" 304 -
"GET /images/eyeballLongOnce.gif HTTP/1.1" 304 -

Open in new window

So, Why can't I access files in content/sidebar?
0
I have the html code shown below. In Firefox, when I click the link to open the spreadsheet, it puts the current window (having the link) into the background. This is quite inconvenient as the user must click on the Firefox icon(s) in the taskbar to find their page when done with the spreadsheet. IE does not send the page to the background.

Note that this page is opened using
window.open('thisProgram.jsp','_blank','scrollbars=1,resizable=1,width=700,height=400,top=0')

Open in new window

and does not have a tab among the other Firefox tabs. Therefore, the user doesn't even have a tab to click on to get their page back to the foreground (nor is there a tab in IE).
<div>
  <a href="tmp/calcFAS701.csv" target="_blank">
  <img alt="" style="vertical-align: middle; border:0" width="16" src="images/Excel.jpg">
  &nbsp;get spreadsheet</a>
</div>

Open in new window

Instead of the above, I tried:

<span onclick="w=window.self;w1=window.open('tmp/mySpreadsheet.csv','_blank');w.focus()">click me</span>

but that ended up bringing into focus some apparently random page in the tab-list.

Is there a way to prevent this page from disappearing into the background when the spreadsheet link is clicked?
0
Hi,

What are the various advnatages, disadvantages and feature differences between MQ vs oracle fusion as middle ware. please advise
0
I am trying to convert a String (which was a response from a Web Service call) into JSON, so that I can extract one string from it. I am new to web services and JSON. I have been trying different combinations of jar files and imports but can't fix the error.

<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@page import="org.apache.commons.*" %>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="net.sf.json.JSONSerializer"%>

<%@page import="org.apache.commons.httpclient.HttpClient"%>
<%@page import="org.apache.commons.httpclient.methods.PostMethod;"%> 

<%

String clientid="a";
String clientsecret="b";
String refreshtoken="c";

String GRANT_TYPE = "refresh_token";
String PARAM_GRANT_TYPE = "refresh_token";

String url="urlforoauth";
HttpClient httpclient = new HttpClient();
String responseText="";

PostMethod post = new PostMethod(url);
post.setParameter("client_id",clientid);
post.setParameter("client_secret", clientsecret);
post.setParameter("refresh_token", refreshtoken);
post.setParameter("grant_type",PARAM_GRANT_TYPE);

httpclient.executeMethod(post);

InputStream is = post.getResponseBodyAsStream();
Scanner scanner = new Scanner(is).useDelimiter("\\A");
responseText=scanner.hasNext() ? scanner.next() : "";

System.out.println(responseText);

JSONObject json = (JSONObject) JSONSerializer.toJSON(responseText);

String oauth_token=json.getString("access_token");

System.out.println(oauth_token);

%>



<html>
<head>

<link rel="stylesheet" 

Open in new window

0
I have code that I need help in adding an If Statement in a JSP.  Below is the original code.  I need to storage submission.getOriginatingForm() into a variable and do an if statement with it down in the middle of the page.  So the following pseudo code would be how I want it:

<section class="container approvalContainer">		
                      <% if (closedApprovalTasks.size() > 0)
            {%>
			<h2><%=submission.getOriginatingForm()%></h2>
            <h3>Previous Approvals:</h3>
                <% for (Task thisTask : closedApprovalTasks)		
			string formname = submission.getOriginatingForm();
                {%>
			<% if (formname == "Corporate Email Access on Personal Mobile Device")
			{%>			                				
				<p><%=thisTask.getName()%>: <%=thisTask.getDeferredResult("Approver Status")%> by <%=thisTask.getDeferredResult("Approver Name")%> (<b><%=thisTask.getDeferredResult("Approver ID")%></b>) at <%=thisTask.getModifiedDate()%><br><b>Stipend Comments: </b><%=thisTask.getDeferredResult("Stipend Comments")%></p>	
			<%else%>					
		<p><%=thisTask.getName()%>: <%=thisTask.getDeferredResult("Approver Status")%> by <%=thisTask.getDeferredResult("Approver Name")%> (<b><%=thisTask.getDeferredResult("Approver ID")%></b>) at <%=thisTask.getModifiedDate()%></p>

			<%}%>	
			<%}%>
                <%}%>
            			
            <%@include file="../../core/interface/fragments/displayBodyContent.jspf"%>
        </section>

Open in new window




<%-- Set the page

Open in new window

0
I am trying to enter an If statement in my if statement using struts.  For some reason, it shows both <p></p> fields in the printout but I am trying to resolve this issue so that I only get one printout.  What am I doing wrong?  Here is my code:

<section class="container approvalContainer">
                      <% if (closedApprovalTasks.size() > 0)
            {%>
            <h3>Previous Approvals:</h3>
                <% for (Task thisTask : closedApprovalTasks)
                {%>
			<s:if test="%{thisTask.getDeferredResult('Stipend Comments') == null)}">
                <p><%=thisTask.getName()%>: <%=thisTask.getDeferredResult("Approver Status")%> by <%=thisTask.getDeferredResult("Approver Name")%> (<b><%=thisTask.getDeferredResult("Approver ID")%></b>) at <%=thisTask.getModifiedDate()%></p>				
				</s:if>
				<s:else>
				<p><%=thisTask.getName()%>: <%=thisTask.getDeferredResult("Approver Status")%> by <%=thisTask.getDeferredResult("Approver Name")%> (<b><%=thisTask.getDeferredResult("Approver ID")%></b>) at <%=thisTask.getModifiedDate()%><br><b>Stipend Comments: </b><%=thisTask.getDeferredResult("Stipend Comments")%></p>
				</s:else>
                <%}%>
            <%}%>
            <%@include file="../../core/interface/fragments/displayBodyContent.jspf"%>
        </section>

Open in new window

0
I am using Apache Tomcat 8.0.15 on Linux Slackware 14.1. I have a server with multiple URLs. In $CATALINA_HOME/webapps I have separate app directories corresponding to each of these URLs.

How to I configure things so that a user just has to type the URL and gets the right app? For example:

enter: http://www.mydomain.com  ---- instead of: http://www.mydomain.com/thisApp
0
Hi Experts

How to find missing packages when using Netbeans IDE 8.1 ?

Is there a kind of "Nuget" administrator to help in findind packages ?

Thanks in advance.
0
Hi,

When i try running below code
class TestExceptionMulti {
	public static void main(String[] args) {
		try {
			System.out.println(10 / 0);
		} catch (ArithmeticException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Open in new window


i see below 2 compilation errors. how to resolve.

No exception of type Exception can be thrown; an exception type must be a subclass of Throwable

The method printStackTrace() is undefined for the type Exception.




class TestMulti2 {
      public static void main(String[] args) {
            try {
                  System.out.println(10 / 0);
            } catch (Exception e) {
                  e.printStackTrace();
            } catch (ArithmeticException e) {
                  e.printStackTrace();
            }
      }
}



above also gives errors
No exception of type Exception can be thrown; an exception type must be a subclass of Throwable
The method printStackTrace() is undefined for the type Exception

please advise
0
if we are multiple catch taking from
parent to child then why we will get Compile time error saying


exception zzz has already been caught
class TestException {
	public static void main(String[] args) {
		System.out.println("st1");
		try {
			System.out.println(10 / 0);
		} catch (Exception e) {
			System.out.println(100 / 2);
		}catch (ArithmeticException e) {
			System.out.println(100 / 2);
		}
		System.out.println("st3");
	}
}

Open in new window



above gives different error as below for some reason?
No exception of type Exception can be thrown; an exception type must be a subclass of Throwable
Not sure what it means by above compilation error?
where below code running fine

class TestException {
	public static void main(String[] args) {
		System.out.println("st1");
		try {
			System.out.println(10 / 0);
		} catch (ArithmeticException e) {
			System.out.println(100 / 2);
		}
		System.out.println("st3");
	}
}

Open in new window

0
Hi,

In java i am not clear on runtime exception and error differences. I read both of these comes under unchecked exception where as exceptions checked by compiler comes under the checked exception.


what is the difference between partiall and fully checked exceptions?
please advise
0
In java is it possible to create my own marker interface?
please advise
0
Hello experties
We have one standard JEE web application built on JSP+ Struts+ Webserices+ Oracle stack. On UI layer we would like to convert current JSP pages ( ~300 Pages) into Responsive web Pages which can be ported on mobile devices and follow almost all (~80%) responsive web design approach. Some dynamic HTML templates are also stored into database which we are using in this application. Customer is asking for cost effective solution which is the top priority in their current business plan hence they do not want to write the application from the scratch using front-end RWD Tech stack i.e.  HTML5, CSS3,JavaScript, jQuery, Bootstrap, Angular,Foundation5 etc.

We know CSS3 media queries are there to make the pages responsive but how feasible it would be if we consider complex JSP page structure with JSP Tags, complex layouts, grids and dynamic HTML templates etc. ? Please suggest if any pointers or throw some light to achieve this?
0
Guess this question would be a common question for an ordinary J2EE project. I have a struts2 project, which require many users with different role to login. after the authentication of the username/password pair, the role information is retrieved from the database, base on the different role of the users, I want to direct the user to the different JSP homepage based on the role. For example, after the user login, admin would go to adminHomepage.JSP and customer go to customerHomepage.JSP,  Since struts2 only return limited constant, like SUCCESS, ERROR, INPUT, etc. is there any way to do something like: SUCCESS_ADMIN, SUCCESS_SALES, SUCCESS_CUSTOMER...etc? such that I can direct the user to the different JSP pages like: adminHomepage.jsp or customerHomepage.jsp?


 <package name="eblast" extends="struts-default">
 <action name="login"
            class="com.xxxxxxx.report.AuthenticationAction"
            method="execute">
            <interceptor-ref name="params"/>
            <interceptor-ref name="timer" />
            <result name="input">/index.jsp</result>
            <result name="success" type="redirectAction">
            <param name="actionName">homepage</param>
            <param name="namespace">/secure</param>
            </result>
            <result name="error">/AccessDenied.jsp</result>
         </action>
    </package>
   
     <package name="secure" extends="struts-default" namespace="/secure">
     <action name="homepage"
     …
0
HI,
I have a MultipartFile in my spring mvc controller which i got by :
       
 MultipartFile file = ((DefaultMultipartHttpServletRequest)request).getFile("file");

The above file in my case is an image file.
Now i am storing file.getBytes(); in database.
now on an another page i want to retrieve this bytes and show the file which in this case is a png file in my jsp page.

How can i do it ?

Thanks
0
HI,
I have the following jsp :
<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    <form action="/flock-retentions/policy" enctype="multipart/form-data" method="post">
    <p>
    Type some text (if you like):<br>
    <input type="text" name="message" size="30">
    </p>
    <p>
    Please specify a file, or a set of files:<br>
    <input type="file" name="file" size="40">
    </p>
    <div>
      <input type="submit" value="Send">
    </div>
    </form>
  </body>
</html>

Open in new window


And following controller method to handle this :
@RequestMapping(value = "/policy")
    public ModelAndView retentionPolicy(@ModelAttribute Retention retention, HttpServletResponse response, HttpServletRequest request) throws IOException {
        ModelAndView mav = new ModelAndView("new");
        return mav;
    }

Open in new window


where retention is :
package org.yatra.code.model;


import org.springframework.web.util.HtmlUtils;

public class Retention {
    private String id;
    private String message;
    private String file;
    private String title;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void parseHtml() {
        message = HtmlUtils.htmlEscape(message);
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}

Open in new window



But when i submit the form all fields the in retention objects are null..

how do i handle it ?

Thanks
0
Dear sirs

I have 3 important projects I need to develop in Java EE, but time won't be in my side.
The projects I am referring to are:
1. Manufacturing System
2. Document Management System
3. Point Of Sale

I have 2 options: Resell an existing product or buy the source code (Preferably written in Java SE/EE)
My preferences:
1. Bilingual (French/English)
2. MySQL/PostGresSQL

Omer
0
Hi,
I am working on below challenge
http://codingbat.com/prob/p165312
I tried my code as below
public String doubleChar(String str) {

  
  for(int i=0;i<str.length();i++){
  char[] arrays=new char[]{str.substring(i, i+1);
  }
  //once get arrays get each character and add one more and make it string
  
}

Open in new window


how to  improve my approach, results and design of this challenge. How do i

make a graphical venn or flow chart or some other relevant diagram to design it

before writing code to decide best strategy?
 Please advise
0
Hi Experts,

I am trying to view PDF in IE using PDF.js(Mozilla) and IE gives different behavior compare to FF.
I debugged and found out that if I put path to another file that invokes servlet there instead of direct url in iframe, IE doesn't invoke servlet.
 
For example, this works in both IE and FF.
<iframe width="900" height="300" src="/abc/efg/pdfservlet" id="pdf_iframe"></iframe>
 
And this is web.xml
<servlet>
    <servlet-name>pdfservlet</servlet-name>
    <servlet-class>org.aaa.bbb.PDFServlet</servlet-class>
  </servlet>
 
 
But this only works in FF not IE. IE just doesn't update PDF content.(The PDFServlet doesn't get invoked.)
 
<iframe width="900" height="300" src="/.../.../viewer.jsp" id="pdf_iframe"></iframe>

How do I fix this in IE10/IE11?

thanks in advance
0
I am trying to create a tool within my Spring MVC webapp where the JSP page takes in text from a user from a textbox, then displays the user text below the textbox with every non-UTF8 decode-able character highlighted in yellow (by taking in the user text as a string, and wrapping every non-UTF8 character with <span style='background:yellow'>(character)</span> and saving the result as form.userDataHighlighted), then display it in the webpage as such:

                                          <TABLE...>
                                          ........
                                          <TR>
                                                <TD valign="top">
                                                      <div>${form.userDataHighlighted}</div>
                                                </TD>
                                          </TR>
                                           </TABLE>

The problem is that the user may enter html content with CSS styling as such:

<html>
    <head>
        <meta http-equiv=Content-Type content="text/plain; charset=utf-8">
        <title></title>

        <style>
                (some user defined styling)
                ......
        </style>
    </head>
   <body>
       ....
    </body>
</html>

and this can affect the styling of the main webpage (for example, change the background color of the main webpage).

Is there a way I can "sandbox" the user text within the JSP so that it cannot affect the main JSP styling (such as display it in some kind of frame)?  I have tried something like:

<table border="1">
<tr>
<td style="width:500px;height:400px">
<iframe …
0
Hi,

I am working on below challenge

http://codingbat.com/prob/p179196


I wrote my code as below and passing all tests.
public boolean lessBy10(int a, int b, int c) {

if((a>=b+10)||(b>=c+10)||(c>=a+10)||(b>=a+10)||(c>=b+10)||(a>=c+10)){

return true;
}

else{
return false;

}
  
}

Open in new window



how to  improve my approach and design of this challenge. How do i make a graphical venn or flow chart or some other relevant diagram to design it before writing code to decide best strategy?
 Please advise
0
how does memory representation of int[][][] a=new int[2][][] looks like.

How above different from below memory representation

int[][][] a=new int[2][0][0];
How above different from below memory representation
int[][][] a=new int[2][1][1];
How above different from below memory representation
int[][][] a=new int[2][2][2];

How matrix representation different from arrya of array representation. Please advise if possible with pictures
0
Hi,

I wonder if 'exit' is not valid keyword in java?
i thought it is  valid keyword to terminate any loop like for, while etc.


why true, false, null are called 'reserved literals' but not 'keywords' under 'reserved words'?
what is meaning of literal?

Please advise.
0
Hi,
I have the following jsp file :
<!DOCTYPE html>
<html>
  <head>
    <title>Create snip</title>

    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
    <script>var require = {config: function (c) {require = c}}</script>


    <link rel="stylesheet" href="/code-snips/resources/lib/codemirror/lib/codemirror.css" />
    <link rel="stylesheet" href="/code-snips/resources/css/new.css"/>
  </head>

  <body>
    <div id="container">
      <div class="dijitDialogTitleBar">
  <div class="dijitDialogTitle">Create snip</div>
      </div>
      <div class="dijitDialogPaneContent">
  <input id="name" type="text" class="title" placeholder="Title (Optional)" />
  <div class="form-group">
    <select id="mode" class="form-control">
            <option id="text/plain" disabled selected style="display: none;"> Syntax</option>
            <option id="text/apl"> APL</option>
            <option id="text/x-ttcn-asn"> ASN.1</option>
            <option id="application/x-aspx"> ASP.NET</option>
            <option id="text/x-asterisk"> Asterisk</option>
            <option id="text/x-csrc"> C</option>
            <option id="text/x-csharp"> C#</option>
            <option id="text/x-c++src"> C++</option>
            <option id="text/x-clojure"> Clojure</option>
            <option id="text/x-cmake"> CMake</option>
            <option id="text/x-cobol"> Cobol</option>
            <option id="text/x-coffeescript"> CoffeeScript</option>
            

Open in new window

0
HI,
I have web page in which user can enter title and comments in two text boxes. Currently user can type any number of chars in both the text box. I want to limit the number he can type to 255.

Here is the jsp for it :
<!DOCTYPE html>
<html>
  <head>
    <title>Create snip</title>

    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
    <script>var require = {config: function (c) {require = c}}</script>


    <link rel="stylesheet" href="/code-snips/resources/lib/codemirror/lib/codemirror.css" />
    <link rel="stylesheet" href="/code-snips/resources/css/new.css"/>
  </head>

  <body>
    <div id="container">
      <div class="dijitDialogTitleBar">
  <div class="dijitDialogTitle">Create snip</div>
      </div>
      <div class="dijitDialogPaneContent">
  <input id="name" type="text" class="title" placeholder="Title (Optional)" />
  <div class="form-group">
    <select id="mode" class="form-control">
            <option id="text/plain" disabled selected style="display: none;"> Syntax</option>
            <option id="text/apl"> APL</option>
            <option id="text/x-ttcn-asn"> ASN.1</option>
            <option id="application/x-aspx"> ASP.NET</option>
            <option id="text/x-asterisk"> Asterisk</option>
            <option id="text/x-csrc"> C</option>
            <option id="text/x-csharp"> C#</option>
            <option id="text/x-c++src"> C++</option>
            <option id="text/x-clojure"> Clojure</option>
     

Open in new window

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!