Rails Edit Form - java

I keep getting this error when i want to enter the edit page "NO ROUTE MATCHES" ,but the weird thing is that when i change the order = #order to #order.listing it goes fine but there is no info to be edited, and i been scratching my head with this error for a while.
This is my Orders Controller:
class OrdersController < ApplicationController
before_action :set_order, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!
# GET /orders
# GET /orders.json
def index
#orders = Order.all
end
# GET /orders/1
# GET /orders/1.json
def show
end
# GET /orders/new
def new
#order = Order.new
#listing = Listing.find(params[:listing_id])
end
# GET /orders/1/edit
def edit
end
# POST /orders
# POST /orders.json
def create
#order = Order.new(order_params)
#listing = Listing.find(params[:listing_id])
#seller = #listing.user
#order.listing_id = #listing.id
#order.buyer_id = current_user.id
#order.seller_id = #seller.id
respond_to do |format|
if #order.save
format.html { redirect_to root_url, notice: 'Pedido creado' }
format.json { render :show, status: :created, location: #order }
else
format.html { render :new }
format.json { render json: #order.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /orders/1
# PATCH/PUT /orders/1.json
def update
respond_to do |format|
if #order.update(order_params)
format.html { redirect_to #order, notice: 'El pedido fue actualizado' }
format.json { render :show, status: :ok, location: #order }
else
format.html { render :edit }
format.json { render json: #order.errors, status: :unprocessable_entity }
end
end
end
# DELETE /orders/1
# DELETE /orders/1.json
def destroy
#order.destroy
respond_to do |format|
format.html { redirect_to orders_url, notice: 'El pedido fue eliminado con exito' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_order
#order = Order.find(params[:id])
end
# Only allow a list of trusted parameters through.
def order_params
params.require(:order).permit(:address, :city, :state)
end
end
My Edit Page:
<h1>Editing Order</h1>
<%= render 'form', order: #order %>
<%= link_to 'Atras', listing_orders_path %>
Form:
<%= form_for(model: [#listing, order], local: true) do |form| %>
<% if order.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(order.errors.count, "error") %> prohibited this order from being saved:</h2>
<ul>
<% order.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= form.label :address %>
<%= form.text_field :address %>
</div>
<div class="field">
<%= form.label :city %>
<%= form.text_field :city %>
</div>
<div class="field">
<%= form.label :state %>
<%= form.text_field :state %>
</div>
<div class="actions">
<%= form.submit %>
</div>
<% end %>
ADDITIONAL INFO:
Routes.rb:
Rails.application.routes.draw do
devise_for :users
resources :listings do
resources :orders
end
end
Rake routes:
Prefix Verb URI Pattern Controller#Action
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
user_password PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
POST /users/password(.:format) devise/passwords#create
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
user_registration PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
POST /users(.:format) devise/registrations#create
listing_orders GET /listings/:listing_id/orders(.:format) orders#index
POST /listings/:listing_id/orders(.:format) orders#create
new_listing_order GET /listings/:listing_id/orders/new(.:format) orders#new
edit_listing_order GET /listings/:listing_id/orders/:id/edit(.:format) orders#edit
listing_order GET /listings/:listing_id/orders/:id(.:format) orders#show
PATCH /listings/:listing_id/orders/:id(.:format) orders#update
PUT /listings/:listing_id/orders/:id(.:format) orders#update
DELETE /listings/:listing_id/orders/:id(.:format) orders#destroy
listings GET /listings(.:format) listings#index
POST /listings(.:format) listings#create
new_listing GET /listings/new(.:format) listings#new
edit_listing GET /listings/:id/edit(.:format) listings#edit
listing GET /listings/:id(.:format) listings#show
PATCH /listings/:id(.:format) listings#update
PUT /listings/:id(.:format) listings#update
DELETE /listings/:id(.:format) listings#destroy
pages_about GET /pages/about(.:format) pages#about
pages_contact GET /pages/contact(.:format) pages#contact
seller GET /seller(.:format) listings#seller
root GET / listings#index
rails_postmark_inbound_emails POST /rails/action_mailbox/postmark/inbound_emails(.:format) action_mailbox/ingresses/postmark/inbound_emails#create
rails_relay_inbound_emails POST /rails/action_mailbox/relay/inbound_emails(.:format) action_mailbox/ingresses/relay/inbound_emails#create
rails_sendgrid_inbound_emails POST /rails/action_mailbox/sendgrid/inbound_emails(.:format) action_mailbox/ingresses/sendgrid/inbound_emails#create
rails_mandrill_inbound_health_check GET /rails/action_mailbox/mandrill/inbound_emails(.:format) action_mailbox/ingresses/mandrill/inbound_emails#health_check
rails_mandrill_inbound_emails POST /rails/action_mailbox/mandrill/inbound_emails(.:format) action_mailbox/ingresses/mandrill/inbound_emails#create
rails_mailgun_inbound_emails POST /rails/action_mailbox/mailgun/inbound_emails/mime(.:format) action_mailbox/ingresses/mailgun/inbound_emails#create
rails_conductor_inbound_emails GET /rails/conductor/action_mailbox/inbound_emails(.:format) rails/conductor/action_mailbox/inbound_emails#index
POST /rails/conductor/action_mailbox/inbound_emails(.:format) rails/conductor/action_mailbox/inbound_emails#create
new_rails_conductor_inbound_email GET /rails/conductor/action_mailbox/inbound_emails/new(.:format) rails/conductor/action_mailbox/inbound_emails#new
edit_rails_conductor_inbound_email GET /rails/conductor/action_mailbox/inbound_emails/:id/edit(.:format) rails/conductor/action_mailbox/inbound_emails#edit
rails_conductor_inbound_email GET /rails/conductor/action_mailbox/inbound_emails/:id(.:format) rails/conductor/action_mailbox/inbound_emails#show
PATCH /rails/conductor/action_mailbox/inbound_emails/:id(.:format) rails/conductor/action_mailbox/inbound_emails#update
PUT /rails/conductor/action_mailbox/inbound_emails/:id(.:format) rails/conductor/action_mailbox/inbound_emails#update
DELETE /rails/conductor/action_mailbox/inbound_emails/:id(.:format) rails/conductor/action_mailbox/inbound_emails#destroy
rails_conductor_inbound_email_reroute POST /rails/conductor/action_mailbox/:inbound_email_id/reroute(.:format) rails/conductor/action_mailbox/reroutes#create
rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show
rails_blob_representation GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show
rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show
update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update
rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create

You have orders set up as a nested resource under listings:
resources :listings do
resources :orders
end
That means -- as you can see from your routes output -- that the URL path for editing an order is:
/listings/:listing_id/orders/:id/edit
I don't think you included the code for the link to the edit page, but my guess is you are using the Rails-generated URL helper, edit_listing_order_path, which takes two parameters: a listing_id and an order ID. If you check that link my guess is you aren't specifying both IDs. The reason I say that is that if you look at the link_to on the edit page:
<%= link_to 'Atras', listing_orders_path %>
It is missing the ID of the appropriate listing record:
<%= link_to 'Atras', listing_orders_path(#listing) %>
I suspect you need to check all the orders paths to ensure you are also specifying the parent listing.
The other thing you likely need to do is load the listing instance in your OrdersController:
def set_order
#order = Order.find(params[:id])
#listing = #order.listing # or from parameters: Listing.find(params([:listing_id])
end

Related

Confused about using grails paginate

I am new to grails and I am a bit confused about how to use <g:paginate>.
I have a table and I want to set the max number of entrees to 10. Most of the examples I find online have used a List and have a set of jobs and services that help create the navigation. I am confused about this because I did not use a list in my controller. The total number of entrees is going through, but every entree is still displayed. If I click on page 2 or a 'next' button, it seems that my controller loses track of the sourceVolume that the user selected to generate this list.
For context - the first page the user sees prompts them to select a source volume - and from there a table is generated that shows a list of all of the entrees(snapshots) in the source volume.
my selectSnapshotVolume.gsp
<g:form class = "myForm" url="[controller:'Vaultrecovery', action:'doRecoveryConfirmation', method:'post']">
<table class = "content-table">
<thead>
<tr>
<th>Select</th>
<th>Cluster</th>
<th>Vserver</th>
<th>Volume</th>
<th>SnapShot</th>
</tr>
</thead>
<tbody>
<g:each in="${destinationVolumes}" var="destinationVolume">
<tr>
<td><g:radio name="snapshot" value="$destinationVolume.snapshot" required="true"></g: radio></td>
<td>
${destinationVolume.cluster}
</td>
<td>
${destinationVolume.vserver}
</td>
<td>
${destinationVolume.volume}
</td>
<td><b>
${destinationVolume.snapshot}
</b></td>
</tr>
<g:hiddenField name="cluster" value="${destinationVolume.cluster}" />
<g:hiddenField name="vserver" value="${destinationVolume.vserver}" />
<g:hiddenField name="volume" value="${destinationVolume.volume}" />
</g:each>
</tbody>
</table>
<div class = "centerMe">
<div class="pagination">
<g:paginate controller='Vaultrecovery' total="${entreeCount.total[0] ?: 0}" />
</div>
</div>
<div class = "centerMeDescription">
<g:submitButton class="submit " name="submit" value="Submit"/>
</div>
</g:form>
and here is my controller. I do not have any services, jobs, or a domain class. I have also cut out parts of the controller that are irrelevant.
class VaultrecoveryController {
def dataSource_model // netapp_model
def dataSource // dataautomation
def mailService
File testFile = new File("/opt/tomcat/work/TEST")
boolean TEST = testFile.exists()
def index() { }
def selectSourceVolume() {
log.info "Vaultrecovery Controller - selectSourceVolume"
def foo = new Sql(dataSource_model)
String SQL
SQL = "SELECT distinct(name) FROM volume WHERE (name NOT LIKE '%_dest%' AND name NOT LIKE 'MDV%' AND name NOT LIKE '%\\_\\_%') ORDER BY name"
log.info "Getting source volumes: " + SQL
def sourceVolumes = foo.rows(SQL)
[sourceVolumes: sourceVolumes]
} // end selectSourceVolume
def selectSnapshotVolume() {
log.info "Vaultrecovery Controller - selectSnapshotVolume"
def sourceVolume = params.srcvolume
log.info "SOURCE VOLUME IS: " + sourceVolume
def foo = new Sql(dataSource)
String SQL
SQL = "SELECT cluster, vserver, volume, snapshot FROM netapp_vault WHERE volume LIKE '%" + sourceVolume + "%' ORDER BY snapshot"
log.info SQL
def destinationVolumes = foo.rows(SQL)
SQL = "SELECT COUNT(cluster) as total FROM netapp_vault WHERE volume LIKE '%" + sourceVolume + "%' ORDER BY snapshot"
def entreeCount = foo.rows(SQL);
[sourceVolume: sourceVolume, destinationVolumes: destinationVolumes, entreeCount: entreeCount]
} // end selectSnapshotVolume
}
You lost the search criteria because the Prev or the Next button did not POST your Source Volume value back to the controller.
I had the same problem in my project. Took me half the day to figure it out. If you check the HTML what the Prev and the Next button is, they only POST back the Max and Offset values back to the controller. Keep this in mind. This kind of project is state-less. So, your action will reset back to the initial state.
Next
I use a private variable to store my last used search criteria. My action checks if the private variable has anything. If so, it use the criteria from the private variable to run the SQL. So, I will get the same records from the page before. I then apply the Max and Offset to get the correct records.
Something like this:
class BookController {
private String _searchString = ''
def index() {
_searchString = (params.searchString == null) ? _searchString : params.searchString
bookList = Book.findAllByName(_searchString, params)
}
}
params.searchString will be null because the Prev/Next button does not POST back the searchString. If it is null, I grab the searchString from the private variable _searchString and use it in my dynamic finders. I am lucky that Grails did not reset the _searchString variable when the Prev/Next calls the action.

Spring how to refresh the page when I received a transaction?

I work with Spring Mvc app to develop a bitcoin wallet and I have the controller definition,
#RequestMapping(value = "/")
public String showBitcoinWallet() {
return "index";
}
This returns the index.jsp page provides the relevant infos,
Till the moment the app is not synchronized to the blockchain, it will refresh in every 3000 ms from the script,
<html>
<body>
<!- some code ->
<!- some code ->
</body>
<script>
<% if(!model.isSyncFinished()) {%>
setTimeout(function () {
window.location.reload(1);
}, 3000);
<% }%>
</script>
</html>
For the sending operation, a pop-up opens and the user execute the submission. This operation refresh the page and updates the info(e.g balance, address etc). In the instance of receiving, the page is not refreshed and only updates if I manually refresh.
I need to refresh the page after the user received the money.
I have a method that returns boolean of the receive execution operation,
public static boolean isMoneyReceived() {
try {
WalletMain.bitcoin.wallet().addEventListener(new AbstractWalletEventListener() {
#Override
public void onCoinsReceived(Wallet w, Transaction tx, Coin prevBalance, Coin newBalance) {
// Runs in the dedicated "user thread".
//
// The transaction "tx" can either be pending, or included into a block (we didn't see the broadcast).
Coin value = tx.getValueSentToMe(w);
// System.out.println("Received tx for " + value.toFriendlyString() + ": " + tx);
// System.out.println("Transaction will be forwarded after it confirms.");
}
});
return true;
} catch (Exception e) {
e.printStackTrace();
} finally {
return false;
}
}
So, the intension will be to write code the in the <script> that if the isMoneyReceived returns true, then, I would need to refresh the page. In that case, I may need to put the method in an iteration say, while and keep on calling with an if condition.
There might be 2nd option to have done it completely in the controller. I have tried to do it in the index.jsp page inside the <script> tag with no success,
<% while(true) {%>
<% boolean moneyReceived = BitcoinWalletController.isMoneyReceived(); %>
<% if(moneyReceived) {%>
// tried to print something ..
<% System.out.println("-----------------------"); %>
<% System.out.println("Hello, Money Received"); %>
<% System.out.println("-----------------------"); %>
<% moneyReceived = false; %>
<% }%>
<%}%>
I ended up getting the error,
HTTP Status [500] – [Internal Server Error]
Type Exception Report
Message java.lang.ClassNotFoundException: org.apache.jsp.WEB_002dINF.jsps.index_jsp
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.WEB_002dINF.jsps.index_jsp
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:176)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:380)
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:742)
How to solve the problem? As mentioned earlier, if i can redirect the page from the Spring controller, that would be fine as well.
The problem with your code is that jsp pages are rendered on the server. So, putting a while loop will pretty much prevent the page from ever getting to the clients browser (and being displayed).
Therefore, the way I suggest is to use an AJAX call to the isMoneyReceived() method and then check the return value using a script.
This is a code sample with jQuery ajax get request:
$("button").click(function(){
$.get("yourTargetInterface", function(data, status){
//your processing code here, with the variable "data" being the response to your request; in this case true or false
});
});
yourTargetInterface should be the interface to your method (e.g. through a servlet, web service, etc.).
You can replace $("button").click with a timeout (e.g. every 3 secs).
Then you can process it with a script and setup the application logic accordingly.

Is it possible to forward 2 requests from 2 different servlets to 1 jsp?

I was trying to do this in my servlet:
Date date = new Date();
request.setAttribute("status", status);
request.setAttribute("date", date);
if (status.equalsIgnoreCase("Incorrect password")|| status.equalsIgnoreCase("Username not found")) {
request.getRequestDispatcher("error.jsp").forward(request,response);
}
else {
request.getRequestDispatcher("success.jsp").forward(request,response);
}
and this inside my success.jsp:
<%
String stat = (String) request.getAttribute("status");
String timestamp = (String) request.getAttribute("date");
%>
<p>Welcome, <%= stat %>! </p>
<p>TimeStamp : <%= timestamp %> </p>
I got a 500 internal server error from the code above then I decided to use a separate servlet for my date object and forwarded the request to the same jsp but the I got a null value after this.
Why is it that my first implementation got a 500 internal server error and how come I got a null value on my second implementation? How can I solve this?

How to populate data into a dropbox based on selections of another dropbox?

I am going to implement a search form as in here. As you can see the first dropdown box is used to select a country. Once a country is selected the list of its cities will be populated into second dropdown list. Please note the second dropdown list is disabled first and will be enabled when it is populated by data.
To implement this, onChange function is used to send the selected value of the first dropdown list to the server and retrieve the results but I do not know how to populate the second dropdown list.
<s:form action="/Cars/find" method="GET">
<s:select id="country"
name="country"
list="#com.example.listOfCountries"
onChange="getCities(this.value)"
/>
<s:select id="city"
name="city"
headerKey="-1" headerValue="Select City"
disabled = "true"
list="{'empty'}";
/>
<s:submit value="Search"></s:submit>
</s:form>
JavaScript function
function getCities(val) {
if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
document.getElementById("carCity").disabled = "false";
document.getElementById("carCity").list = xmlhttp.responseText;
}
}
xmlhttp.open("get", "../Search/findCities?country=" + val, false);
xmlhttp.send();
}
Java
my Java function add the list of cities to the following field
private List<String> cities = new ArrayList();
And show them into result page using
${cities}
Output of the xmlhttp.responseText
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
[{, 'Aberdeen', 'Aberystwyth', 'Aldershot', 'Amesbury', 'Anglesey', 'Ashford', 'Aylesbury', 'Ayr', 'Banbury', 'Barnstaple', 'Barrow In Furness', 'Basildon', 'Basingstoke', 'Bath', 'Bedford', 'Belfast', 'Birkenhead', 'Birmingham', 'Blackpool', 'Bolton', 'Bournemouth', 'Bracknell', 'Bradford', 'Brighton', 'Bristol', 'Bromley', 'Burnley', 'Burton Upon Trent', 'Bury St. Edmunds', 'Caernarfon', 'Cambridge', 'Cardiff', 'Carlisle', 'Carmarthen', 'Chatham', 'Chelmsford', 'Cheltenham', 'Chester', 'Colchester', 'Colwyn Bay', 'Coventry', 'Crawley', 'Croydon', 'Darlington', 'Dartford', 'Derby', 'Derry', 'Doncaster', 'Dover', 'Dudley', 'Dumbarton', 'Dumfries', 'Dundee', 'Durham Tees Valley', 'Eastbourne', 'East Kilbride', 'East Midlands', 'Edinburgh', 'Elgin', 'Epsom', 'Exeter', 'Falkirk', 'Falmouth', 'Fareham', 'Farnborough', 'Feltham', 'Fishguard', 'Fraserburgh', 'Glasgow', 'Glasgow Prestwick', 'Gloucester', 'Godalming', 'Great Yarmouth', 'Grimsby', 'Guernsey', 'Guildford', 'Gwynedd', 'Hamilton', 'Hampton', 'Harlington / Hayes', 'Harlow', 'Harrogate', 'Harrow', 'Hastings', 'Helston', 'Hemel Hempstead', 'Hereford', 'High Wycombe', 'Hoddesdon', 'Holyhead', 'Huddersfield', 'Hull', 'Humberside', 'Ilchester', 'Inverness', 'Ipswich', 'Isle of Man', 'Jersey', 'Kent', 'Kilmarnock', 'Kings Lynn', 'Kirkcaldy', 'Lancaster', 'Lancing', 'Leeds', 'Leicester', 'Lincoln', 'Liverpool', 'Livingston', 'Llandudno', 'London', 'London City Airport', 'London Gatwick Airport', 'London Heathrow Airport', 'London Luton Airport', 'London Stansted Airport', 'Lowestoft', 'Luton', 'Macclesfield', 'Maidstone', 'Manchester', 'Mansfield', 'Middlesbrough', 'Milton Keynes', 'Motherwell', 'Newbury', 'Newcastle Upon Tyne', 'Newport', 'Newquay', 'Northampton', 'Northwich', 'Norwich', 'Nottingham', 'Oldbury', 'Oldham', 'Oxford', 'Paisley', 'Pembroke', 'Penrith', 'Penzance', 'Perth', 'Peterborough', 'Peterhead', 'Plymouth', 'Poole', 'Portsmouth', 'Preston', 'Reading', 'Redditch', 'Reigate', 'Rochdale', 'Rochester', 'Romford', 'Rutland', 'Salisbury', 'Sheffield', 'Shetland Islands', 'Shrewsbury', 'Slough', 'Southampton', 'Southend', 'Southend-on-Sea', 'Stafford', 'Staines', 'St. Albans', 'Stansted', 'Stevenage', 'Stirling', 'Stockport', 'Stockton On Tees', 'Stoke-On-Trent', 'Stranraer', 'Stratford Upon Avon', 'Sunbury', 'Sunderland', 'Sutton', 'Swansea', 'Swindon', 'Tamworth', 'Taunton', 'Teesside', 'Telford', 'Thetford', 'Tonbridge', 'Torquay', 'Truro', 'Uxbridge', 'Wakefield', 'Walsall', 'Warrington', 'Warwick', 'Watford', 'Wellingborough', 'Welshpool', 'Welwyn Garden City', 'West Bromwich', 'Weston-Super-Mare', 'Wetherby', 'Weymouth', 'Wigan', 'Woking', 'Wolverhampton', 'Worcester', 'Workington', 'Worthing', 'Worthing Lancing', 'Yeovil', 'York', }]
</body>
</html>
It appears that you are on the right track, however, I would suggest that you take a look at using a framework like jQuery because this task would be much simpler.
First off, looking at the xmlhttp.responseText, it appears that you need to change your struts configuration so that the output is not a full HTML document. The way the server is returning this response is going to make it very difficult for you to process. A quick way to make this work the way you want is to have the server generate a populated select tag. When your source page renders, place a disabled select tag inside of a div element that you can reference by an ID like so -
<div id="dynamicSelectTagHolder">
<select name="foo" disabled="true" />
</div>
Once the server has generated a result, you can assign the contents of the div#dynamicSelectTagHolder to the text returned by the server using innerHTML like so -
document.getElementById("dynamicSelectTagHolder").innerHTML = xmlhttp.responseText;
Be forewarned you may run into many problems with your current approach. It has been a while for me, but if I remember correctly, innerHTML and getElementById is not something that works perfectly across all browsers. That is why I suggest looking into jQuery.

How to call action with parameters of JSP Servlet from JavaScript?

function printthis()
{
var content_vlue = document.getElementById('print_content').innerHTML;
var target= 'printValue?value1='+content_vlue;
document.forms[0].action = target;
document.forms[0].submit();
}
<div id="print_content">hello i am good</div>
For frontend I am using JSP. While executing this code to get the value in servlet
String msg = request.getParameter("value1");
While executing this code the browser url changes to printValue?
But I am unable to get the value of value1
Please suggest me...
Seems you are missing value1='+content_vlue from the request
try this and see
var target= "'printValue?value1="+content_vlue+"'";
Create a hidden variable inside your form like this
<form ..>
....
<input type="hidden" id="value1" name="value1"/>
</form>
and modify javascript function to this .
function printthis()
{
var content_vlue = document.getElementById('print_content').innerHTML;
document.getElementById('value1').value = content_value;
var target= 'printValue';
document.forms[0].action = target;
document.forms[0].submit();
}
Hope this will work for you.

Categories

Resources