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 have a web application that is deployed in wildfly 12, and I need to precompile the jsp for production, in the forums I saw that jspc is not longer  supported for jboss, also y tried maven plugin with no success.

i tried using management deployment and later do the explode forn the web console but the jsp isn't compiled
Also i couldn't find a command to do it from the hot-deployment, like glassfish --precompilejsp parameter.

how to do the precompilation of the jsp in wildfly?
0
Get your problem seen by more experts
LVL 12
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

I have a Tomcat app. Recently, I've updated the connection pool, in order to use Tomcat's jdbc-connection pool. In my Windows developing machine, everything works fine, but now that I'm trying to implement this on my Linux Server, I get this exception (see title) when ever my app tries to connect to MySQL.

I'm using "Easy Tomcat 7" which is supposed to be the same as the regular version of Tomcat, only it comes with the CPanel software.

I just need this database to be available for this app (not multiple app's).

This is my java DB class:

public class DBUtil {

static DataSource ds;
static {
    try {
        Context context = new InitialContext();
        ds = (DataSource)context.lookup("java:comp/env/jdbc/rhwebDB");
    } catch (NamingException e) {
        e.printStackTrace();
        System.out.println("DBUtil.NamingException" + e);
    } catch(Exception e) {
        System.out.println(e);
    }
}

public static Connection getConnection() throws SQLException {
    return ds.getConnection();
}

Open in new window


This is my context.xml file, which is located on myAppDirectory/META-INF folder

<?xml version="1.0" encoding="UTF-8"?>

<Context>
<Resource
    name="jdbc/rhwebDB"
    auth="Container"
    type="javax.sql.DataSource"
    factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
    testWhileIdle="true"
    testOnBorrow="true"
    testOnReturn="false"
    validationQuery="SELECT 1"
    validationInterval="30000"
    timeBetweenEvictionRunsMillis="30000"
    maxActive="20"
    minIdle="3"
    maxIdle="15"
    maxWait="10000"
    initialSize="3"
    removeAbandonedTimeout="60"
    removeAbandoned="true"
    logAbandoned="true"
    minEvictableIdleTimeMillis="30000"
    username="dbuser"
    password="dbpassword"
    driverClassName="com.mysql.jdbc.Driver"
        url="jdbc:mysql://127.0.0.1:3306/rhmexweb_rhweb"/>
</Context>

Open in new window


I don't use WAR files. I just upload files to my server and re-start tomcat when needed, which normally works just fine.

In case this is relevant too, Tomcat's server.xml file has this settings for this website. I've also tried adding parameter copyXML="true", with no luck so far:

<Host name="rhweb.mx" appBase="webapps">
          <Alias>www.rhweb.mx</Alias>
          <Context path="" reloadable="false" docBase="/home/rhmexweb/public_html" debug="1" />

Open in new window


Here's the full stacktrace I get when my app tries to establish a connection with MySQL:


Open in new window

0
Greetings,

I am  working on servlet  project and I  had made a jsp form in my project.  I have fetch the data in my dropdownlist using jsp code.  But the error is that when I select dropdownlist
I  want  to fetch the data in my multiple textbox according to my sql database column.

Please can you help me?
0
Will not display the image that retrieved from DB (as blob)  in Chrome ? But working fine with Firefox.
0
I downloaded a working demo but when I integrated it with the registration page made by me I am getting an error on adding a new user:

[Field error in object 'user' on field 'userProfiles': rejected value [3]; codes [typeMismatch.user.userProfiles,typeMismatch.userProfiles,typeMismatch.java.util.Set,typeMismatch]; arguments
[org.springframework.context.support.DefaultMessageSourceResolvable: codes [user.userProfiles,userProfiles]; arguments []; default message [userProfiles]]; default message
[Failed to convert property value of type 'java.lang.String' to required type 'java.util.Set' for property 'userProfiles'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type
[com.idev.tpt.model.UserProfile] for property 'userProfiles[0]': no matching editors or conversion strategy found]]

JSP File:

<form:form id="userForm" action="newuser" modelAttribute="user">
    <form:input type="hidden" path="id" id="id" />
    <div class="form-group">
        <form:input type="text" path="firstName" id="firstName" placeholder="First Name" class="form-control input-sm" />
    </div>
    <div class="form-group">
        <form:input type="text" path="lastName" id="lastName" placeholder="Last Name" class="form-control input-sm" />
    </div>
    <div class="form-group">
        <c:choose>
            <c:when test="${edit}">
                <form:input type="text" path="ssoId" id="ssoId" placeholder="SSO ID" 

Open in new window

0
I created one application in netbeans 8.2 now i want to deploy this application in weblogic for that i created weblogic.xml but when i validate its giving me following error at the same time when i deployed as it is then in weblogic it is showing me Unable to access the selected application.,Exception in AppMerge flows' progression,Unmarshaller failed when i validate weblogic.xml its showing me below error,im using apache tom cat in server side weblogic java version is java version "1.7.0_71" where in my windows it is 1.8.0_161

Checking file:/D:/GODBFILES/NETBEANS%20PROJECTS/NetBeansProjects/EmployeeRegistration/web/WEB-INF/weblogic.xml...
schema_reference.4: Failed to read schema document 'file:/C:/Program%20Files/glassfish-4.1.1/glassfish/lib/schemas/weblogic-web-app.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. [2]
cvc-elt.1: Cannot find the declaration of element 'weblogic-web-app'. [2]
schema_reference.4: Failed to read schema document 'file:/C:/Program%20Files/glassfish-4.1.1/glassfish/lib/schemas/weblogic-web-app.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. [3]
schema_reference.4: Failed to read schema document 'file:/C:/Program%20Files/glassfish-4.1.1/glassfish/lib/schemas/weblogic-web-app.xsd', because 1) could not find the document; 2) the document could not be read; 3) the …
0
Here is my html code where i creating dynamic textbox for insert using jsp
function getinput()
{
index ++;
var singleRecord = "";
singleRecord += " Employee_id : <input type='text' READONLY name='txt_Employee_id"+index+"'value='<%=request.getParameter("employee_id")%>'>";
singleRecord += " Project_name : <input type='text' name='txt_project_name"+index+"'>";
singleRecord += "Project/Task : <input type='text' name='txt_Header"+index+"'>";
singleRecord += "Department : <input type='text' name='txt_Department"+index+"'>";
singleRecord += "Description : <input type='text' name='txt_description"+index+"'>";
<!--singleRecord+="Date : <input type='date'  name='datainsertdate"+index+"'>"; --->
singleRecord += "<hr/>";
$("#inputs").append(singleRecord);
$("#count").val(index);
}

</script>

</head>

<body background="123-slideshow\blue_background.jpg">
<form action="EmployeeVendorValidation.jsp" method="post">

   
     <br><br><br><br>    
<input type="hidden" name="count" id="count"/>



<div id="inputs">
</div>
<button type="button" onclick="getinput()" class="button button5">Add</button>

&nbsp;
<button type="submit" class="button button2">Submit</button>

jsp:

 Class.forName("oracle.jdbc.driver.OracleDriver");
          Connection con=DriverManager.getConnection("jdbc:oracle:thin:@172.18.114.213:1821:godb","xe","ex");
       PreparedStatement ps = con.prepareStatement("insert into employee_task values(?,?,?,?,?,?)"); …
0
How to delete products from shopping cart when user session ends (or Logout in ) in jsp web application.When you then add a product to your cart (not logged in) and then decide to login and go to the checkout, I now have 2 products in the basket. Is there a way to not store products in the basket when you logout?

I know that this is a cookies issue, but is there a way to remove products from the cart when logging out?

Following is code what i have tried.




product.jsp
<link href="style.css" rel="stylesheet" type="text/css" media="all" /> 
<div class="cart"> 
						<form action="#" method="post" class="last"> 
							<input type="hidden" name="cmd" value="_cart" />
							<input type="hidden" name="display" value="0" />
							<button class="w3view-cart" type="submit" name="submit" value=""><i class="fa fa-cart-arrow-down" aria-hidden="true">cart</i></button>
						</form>  
					</div>
					
						<div class="item" style="width: 30%">
										<div class="glry-w3agile-grids agileits"> 
											<div class="new-tag"><h6>20% <br>Off</h6></div>
											<a href="products4.jsp"><img src="s3.jpg" alt="img"></a>
											<div class="view-caption agileits-w3layouts">           
												<h4><a href="products4.jsp">Nylon Shuttle</a></h4>
												<p>Lorem ipsum dolor sit amet consectetur</p>
												<h5>$56</h5>
												<form action="#" method="post">
													<input type="hidden" name="cmd" value="_cart" />
													<input 

Open in new window

0
I have a jsp page using struts tag as below:
<html:form action="/actions/graphics/job/attachFile/confirm">
<html:cancel value="Cancel" styleClass="buttons"></html:cancel>
<html:submit value="Confirm"/>
</html:form>

Open in new window

     
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
	{
		ActionForward actionForward = SessionChecking.checkUserBean(mapping, request);
		if (actionForward != null)
			return actionForward;

		if (isCancelled(request))
		{
                 //do something here
                }
               //......
     }//execute

Open in new window

it works very well in production for years, now I am trying to change the looking of the button by integrating with bootstrap.
When I only changed the looking of button confirm, it looks like this:
confirm_button_only.pngat this moment, both buttons are functioning.

however, when I tried to change the looking of both buttons, it looks like this:
confirm_cancel_both.png
             <html:form action="/actions/graphics/job/attachFile/confirm">
		<button type="submit" id="cancel" name="cancel" class="btn btn-default" value="Cancel"  > Cancel</button>
		<button type = "submit" id="submit" class ="btn btn-primary" value="Confirm"> Confirm</button>
		</html:form>		

Open in new window

they both looks good, but the problem is both buttons are doing the same job, which means they both have the CONFIRM function , no more CANCEL function.

then I tried a little modification for experiment:
             <html:form action="/actions/graphics/job/attachFile/confirm">
		<button type="button" id="cancel" name="cancel" class="btn btn-default" value="Cancel"  > Cancel</button>
		<button type = "submit" id="submit" class ="btn btn-primary" value="Confirm"> Confirm</button>
		</html:form>	

Open in new window

the problem for this code is the CANCEL button does NOT work at all regardless how many time I click on it.

can anybody help me on this? all I want is just make the CANCEL button looks as big as the CONFIRM button but keep the original functioning.
I think the real question would be : how to transfer the value of CANCEL button to the HttpServletRequest such that the function isCancelled(request) can return true?
by name="cancel" ?  value="Cancel" ? or type="cancel"?
0
I am dealing with datasource in a jsp page and getting

 javax.servlet.jsp.JspException: 'dataSource' is null

what to do in case I am not having exposure to Datasource. I can't attach the code as it is confidential.
0
Cloud Class® Course: C++ 11 Fundamentals
LVL 12
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

I am trying to convert some coldfusion code to jsp and there are some tags like cfargument,cf:loop,cf:return,cf:location.. can anybody tell me what to use in place of these tags in jsp?
0
Hi, I've a Struts 1.x web Application and we have new enhancement we need to redirect to some other application for authenticating and  authorization. In detail, we need to remove our app login page and need to redirect to some other website for login page. I'm using response.sendRedirect(https://xxx.com) and its redirecting to other website but before we display our home page we need to validate their response by calling two times their website. My question is how can I get their website response paramers to validate. Please help us. Thanks!
0
Hi,

I want help on getting data from sql server to Java/JSP page.  I am new to Java/jsp, and need some help with some sample code.

I have a stored proc. [getemployee] which is retrieving FirstName,LastName,EmailAddress. I need to use this stored proc on Java/jsp to show details on jsp page.

Thank you so much for help!
0
I am using jsp tag library based on com.jenkov.prizetag . how can I make it keyboard accessible
0
If i have a rest controller in spring boot how can I validate the contract that comes in if certain values of the parameters need to have certain values??? ANy code examples are appreciated!
0
What is the best technology to create a new shopping website? Like JSP, bootstrap, aspx, angular, PHP etc…
0
I had this question after viewing Retain the value of Drop down box in jsp.
I tried the below code but i'm getting error : alloc_Type is undefined on refresh.
<%
 String riskTypeValue = request.getParameter("riskType");
if(riskTypeValue == null)riskTypeValue = "0";

String allocTypeValue = request.getParameter("allocType");
if(allocTypeValue == null)allocTypeValue = "0";
%>

<script>
function retainValue(){
      //alert("retainValue "+alloc_Type +" && " +risk_Type);
    var element1 = document.forms[0].allocType;
    for(x = 0; x < element1.length; x++){
            if(element1.options[x].value == "<%=alloc_Type%>")
            {
                  element1.options[x].selected = true;
                  break;
            }
    }
    var element2 = document.forms[0].riskType;
    for(x = 0; x < element2.length; x++){
            if(element2.options[x].value == "<%=risk_Type%>"){
                  element2.options[x].selected = true;
                  break;
            }
    }
}
</script>


<tr>
                        <td>&nbsp;</td>
                        <td class="smalltext" width="150px"><b>Allocation Type:</b></td>
                        <td class="smalltext">
                               <select id="allocType"
                                          class="filter_smalltext" name="allocType">
                                    <c:forEach items="${dataBO.alloc_types}" var="allocTypes">
                                          <option value="${allocTypes.key}" ${ allocTypes.key eq dataBO.alloc_type ? …
0
I have a jsp page which contain drop downs and two buttons. One button for Upload and other is Run button. I want to retain the value of drop downs even after the Upload is clicked and submitted the form so that the same values should pass for Run button . I used the below code.

<select name="riskType" class="filter_smalltext" onchange="regAuthChange();">
                                          <!-- <option value=0>Select...</option>
                                          <option value="CR">CR</option>
                                          <option value="MR">MR</option>
                                          <option value="BOTH">Both</option> -->
                                          <option value="" selected="selected">Choose One</option>
                                          <option value="<%if(request.getParameter("riskType").equals("CR")) {out.println('selected="selected"'); } %>">CR</option>
                                          <option value="<%if(request.getParameter("riskType").equals("MR")) {out.println('selected="selected"'); } %>">MR</option>
                                          <option value="<%if(request.getParameter("riskType").equals("BOTH")) {out.println('selected="selected"'); } %>">BOTH</option>
                              </select></td>



But i am getting this error :
jv_allocation_process.jsp:16:18: Error in "jv_allocation_process.jsp" at line 401: Invalid character constant
<%@ include file="templates/jv_allocation_process.jsp" %>
                 ^-----------------------------------^

        at weblogic.servlet.jsp.JavelinxJSPStub.reportCompilationErrorIfNeccessary(JavelinxJSPStub.java:247)
        at weblogic.servlet.jsp.JavelinxJSPStub.compilePage0(JavelinxJSPStub.java:183)
        at …
0
Tomcat 6 TLS1.2 enabled but still using SSL2 when opening an HTTP connection

Greetings, newbie here, so I might need help formatting the question properly.

I have a application running under Tomcat 6 that needs to run TLSv1.2.
I have install the JAVA runtime edition 6.0.181 which supports TLSv1.2.
I have configured the server.xml file to use TLSv1.2 with connections to clients and wireshark shows TLSv1.2 connections to the client when they are loading pages. But one of the pages makes an API call by opening a HttpURLConnection which also needs to use TLSv1.2 and I am unable to make that work. Wireshark shows that outgoing API call as SSLv2 and the Tomcat log show an "Connection reset" error.


This is the server.xml connector that comes so close.

<Connector
                                protocol=”org.apache.coyote.http11.Http11AprProtocol”
                                port=”443” maxThreads=”200”
                                scheme=”https” secure=”true” SSLEnabled=”true”
                                SSLCertificateFile=”C:\somefolder\cert2017.crt
                                SSLCertificateKeyFile=”C:\somefolder\cert.pem”
                                SSLVerifyClient=”optional” sslEnabledProtocols=”TLSv1.2”/>


Here is the httpconnection code that needs to use tlsv1.2 to work:


String url = " https://www.tlsv12testsite/process.do ";  

            String agent = "Mozilla/4.0";
            String type = "application/x-www-form-urlencoded";
 …
0
Cloud Class® Course: Microsoft Windows 7 Basic
LVL 12
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

I'm calculating values (based on input from one JSP) in a method in my Controller class and trying to pass it to another different JSP page using ModelAndView but I'm getting a weird `NumberFormatException` that I think refers to the value at line 249 from error below, ` 249:    <c:out value="${housepricesList.housePrice}"/>`:
    java.lang.NumberFormatException: For input string: "housePrice"

Open in new window

as well as another exception:
    2018-03-19 12:39:14.439 ERROR 2452 --- [nio-8080-exec-9] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [An exception occurred processing JSP page /houseprice.jsp at line 249

    246:     
    247: 
    248: <c:forEach items="${housepricesList}" var="HousePrice">     
    249:    <c:out value="${housepricesList.housePrice}"/>
    250:    <c:out value="${housepricesList.number_of_houses}"/>
    251: </c:forEach>
    252: 

Open in new window

I'm getting a latitude and longitude from one JSP page, passing it to a method in my Controller where I use the lat & long values to query a database to return house prices within a 1km radius of initial latitude and longitude. I want to pass this returned information (`housePrice` and `number_of_houses`) to another JSP page. However the page won't load and the errors above are displayed in the console.

Controller Class
    	@RequestMapping(value = "/parseHousePrice", method = RequestMethod.POST)
	public 

Open in new window

0
i'm trying to reload user privileges dynamically.

i'm trying to achieve custom authorization mechanism via MethodSecurityExpressionOperations or GrantedAuthority to secure the URL and authorize the URL based on the conditions.

i come across two flavours of Spring to handle this one is via MethodSecurityExpressionOperations and the other is via GrantedAuthority - createAuthorityList

i am not sure which one is better and which one to be used in the case of dynamic reloading of user privileges where one user privilege has been updated by another user dynamically while the user is working on...

Thanks.
0
Difference between Servlet Filter vs Spring Security Filter ?

Some says security filter just authenticates the user, where as servlet filter authorizes the request

Need code snippet to understand the structure of both and the differences.
0
Spring Boot Version: 2.0
Spring Version: 5.0.4

Facing the following issues on trying to implement AccessDecisionManager

1. When used

public class WebConfig implements WebMvcConfigurer

Issue:  uanble to override protected void configure(HttpSecurity http) throws Exception {

2. When used

public class WebConfig extends WebSecurityConfigurerAdapter {

Issue: unable to override the following

a. public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
b. public void addResourceHandlers(ResourceHandlerRegistry registry) {
c. public void addInterceptors(InterceptorRegistry registry) {

3. Throws error "java.lang.IllegalStateException: No ServletContext set" when used as below

public class WebConfig extends WebSecurityConfigurerAdapter implements WebMvcConfigurer {

URL for reference:  http://www.baeldung.com/spring-security-custom-voter

@Bean
public AccessDecisionManager accessDecisionManager() {
    List<AccessDecisionVoter<? extends Object>> decisionVoters
      = Arrays.asList(
        new WebExpressionVoter(),
        new RoleVoter(),
        new AuthenticatedVoter(),
        new MinuteBasedVoter());
    return new UnanimousBased(decisionVoters);
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
    ...
    .anyRequest()
    .authenticated()
    .accessDecisionManager(accessDecisionManager());
}
0
RequestHandlerInterceptor or AccessDecisionVoter which gets called first

I'm working on spring boot application and would like to know RequestHandlerInterceptor or AccessDecisionVoter which gets invoked first
0
Where i can download a sample or demo application which has the following..Any link would be useful

1. Source code
2. Sample SQL file to populate the data in mysql table or json to populate NoSQL
3. Uses Ajax in the front-end to send and receive responses
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
>