Passing parameters between JSPs
Please bear with me here, I'm a student and new to Java Server Pages. If I'm being a complete idiot, can someone give me a good link to a tutorial on JSP, since I've been unable to find info on this anywhere.
Okay, here goes...
I'm using Netbeans and trying to pass an object that connects to a database between the pages, otherwise I'd have to reconnect to the database every time a new page is displayed.
Using Netbeans, you can view each page as "jsp", in "design" view, or view the Java code. In the Java code is the class that extends an AbstractPageBean. The problem is that I'd like to pass parameters, but there is no object representing the class and so I can't just access the instance variables.
Can anyone tell me how to do this?
Asked by: Daniel470 | Posted: 28-01-2022
Answer 1
You can put it in a session JSP tutorial, Sessions.
But frankly, you don't put database connections in a session. They're a scarce resource. You'd be better off using some pooling mechanism like in Tomcat JNDI database pooling example.
I personally would put all that java code in a class and use that class:
java:
public class FooRepo {
public static Foo getFoo(Long id) {
// Read resultSet into foo
}
}
jsp:
Foo = FooRepo.getFoo( id as stored in JSP );
// display foo
If you start playing with JSP I strongly recommend using a book. Creating a working JSP is very, very easy but creating a readable, maintainable JSP is hard. Use JSPs for the view, and not for the logic.
As for what book; go to a bookstore. I personally like the core java series and the Head First series. The last series is very accessible but also thorough.
I understand a book is expensive but investing in a book will help you understand the fundamentals which will help you if you move to struts, spring-mvc, wicket, JSF or whatever other framework you will use in the future.
Answered by: Edgar603 | Posted: 01-03-2022Answer 2
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html is a J2EE tutorial with parts of it talking about JSP as well
one more JSP tutorial from sun : http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPIntro.html
Answered by: Grace899 | Posted: 01-03-2022Answer 3
I second the suggestion for the Head First book on JSP and Servlets. Don't be put off by the cutesy presentation, it's very thorough and the manner in which the information is presented is very effective both in terms of making it easy to learn, and helping it to 'stick'.
You could consider taking the Sun Java Web Component Developer certification exam, it's a good way to force yourself to learn the material thoroughly. Unfortunately, you'll need to take the Sun Java Programmer certification first.
Answered by: Ryan805 | Posted: 01-03-2022Similar questions
java - Spring 3.0M4 and passing objects as parameters to POST
I'm quite sure this has to be in the docs somewhere, but I've looked for days and haven't spotted it. I'm probably staring myself blind when it's right in front of me, so sorry for asking an abvious question, but....
@RequestMapping(method = RequestMethod.POST)
public ModelAndView post(@ModelAttribute("user") User user) {
ModelAndView mav = new ModelAndView(jsonView);
//....
return mav;
}
java - Struts - Passing parameters between action
I have got two actions - ActionA and ActionB, Im trying to invoke ActionB from the result of ActionA using 'action' tag in the following way
<s:action namespace="/myNameSpace" name="actionB" executeResult="true">
<s:param name="param1" value="Value1"/></s:action>
The tag is invoking 'actionB' and Im getting the result from ActionB included into the res...
java - Passing parameters to AXIS web service
I have an AXIS servlet which deployed on an apache tomcat server on windows.
I wrote a web service which I want to run on AXIS.
When I want to deploy my web service, I make a jar file from the classes, and then I copy them to "axis\WEB-INF\lib" directory. Then I deploy the web service using a wsdd file.
My question is - how can I pass parameters to the web service, and how can I read them?
The only web.xml fi...
java - Passing Object Parameters for TestNG methods?
Here is my situation.
Before my tests are run, in the beforesuite, I instantiate a bunch of "environment objects" These objects get created based on my environment configuration file. It is my tests that will actually be using these environment objects. The problem is how can I pass them to the tests.
Your first impulse might be to use a data provider, which will pass the correct objects to the test. Th...
java - passing parameters to urls in struts2?
I am working with a struts2 project and i need to pass parameters through url... this is the code that i have written
<s:url action="submit/CalculatePoints" includeParams="get" var="playerX" >
<s:param name="winnerNo" value="player2"/>
it was refernced by following code
<a href="<s:property value="#playerX" />">
I expec...
java - Passing parameters to the view
In my RCP application, I have a View with a TreeViewer for Navigation on the left side and a Folder for my views on the right side. The Perspective looks like this:
public void createInitialLayout(IPageLayout layout) {
layout.setEditorAreaVisible(false);
layout.setFixed(false);
layout.addStandaloneView(NavigationView.ID, false, IPageLayout.LEFT, 0.7f, layout.getEditorArea());
...
ant passing all parameters to a java task
Is there a way to pass all ant command-line parameters as properties to a java task ?
For example :
ant -Dprop1=value1 -Dprop2=value2 ... -file build.xml myTarget
<target name="myTarget">
<java classname="MyClass">
<sysproperty ... all properties>
</java>
</target>
So the started jvm will have all properties passed from the ant com...
java - passing input parameters to url
I have to pass input parameters to a particular url. I use httpClient to extract the url.
I used Live HttpHeaders to see the input parameters and got this below parameters.
{"email":"3rd.ik@gmail.com","password":"etah","meta":{"screen_resolution":{"height":1080,"width":1920}}}
Usually I use List and pass the input parameters like this,
List <NameValuePair> nvps = new ...
REST passing Parameters with Java
I've built a REST webservice with some webmethods.
But I don't get it to work passing parameters to these methods.
I.E.
@GET
@Path("hello")
@Produces(MediaType.TEXT_PLAIN)
public String hello(String firstName, String lastName){
return "Hello " + firstname + " " + lastname
}
How would I invoke that method and how to pass the parameters firstname and lastname?
I tried something ...
Passing arrays as method parameters in Java
The following code uses simple arrays of String in Java.
package javaarray;
final public class Main
{
public void someMethod(String[] str)
{
System.out.println(str[0]+"\t"+str[1]);
}
public static void main(String[] args)
{
String[] str1 = new String[] {"day", "night"};
String[] str2 = {"black", "white"};
//Both of the above statements are valid.
...
java - How to assign Date parameters to Hibernate query for current timezone?
When you assign a date to a named SQL parameter Hibernate automatically converts it to GMT time. How do you make it use the current server timezone for all dates?
Lets say you have a query:
Query q = session.createQuery("from Table where date_field < :now");
q.setDate("now", new java.util.Date());
"now" will be set to GMT time, while "new Date()" gets your current server time.
c# - How to analyse .exe parameters inside the program?
I have a program that can have a lot of parameters (we have over +30 differents options).
Example:
myProgram.exe -t alpha 1 -prod 1 2 -sleep 200
This is 3 Commands (from command pattern object at the end) that each contain some parameters. Inside the code we parse all command (start with -) and get a list of string (split all space) for the parameters. So in fact, we have : string-->Collection ...
java - How can I validate parameters without creating a separate dialog?
I'm going to make an application (in Swing) that uses a tree to visualize a data structure (JTree). A tree will be on the left side of a window. The user will be able to browse a tree. The parameters of every tree node will be displayed on the right side of the window.
The example windows will be looking like this
===========================
| tree panel | data panel |
| | |
| ...
Java String Parameters
I'm coming from a .net background and want to know the accepted way of creating a method that returns a boolean and modifies a string that was passed in via parameter. I understand Strings are immutable in Java so the below snippet will always produce an empty string. I am constrained to return boolean only. Exceptions can't be thrown. If I need to wrap the String class in, say, a StringHolder, what package could I find th...
java - How do I access init parameters from a JSP2 tag file?
I'm trying to create a jsp tag file but it fails to compile when I try to use pageContext.getServletConfig().getInitParameter("myInitParam")
I'm using tomcat and when I try to view a page including the file I get a jasper compile error pageContext cannot be resolved. I've also tried just using getInitParameter but it fails also. I can use the request object so I know everything else is fin...
Meaning of serial port parameters in Java?
I'm a beginner in Java. I'm reading data from the serial port. I got
serialPort.setSerialPortParams(
9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
What is the meaning of 9600, DATABITS_8,STOPBITS_1 and PARITY_NONE?
java - How do I correctly decode unicode parameters passed to a servlet
Suppose I have:
<a href="http://www.yahoo.com/" target="_yahoo"
title="Yahoo!&#8482;" onclick="return gateway(this);">Yahoo!</a>
<script type="text/javascript">
function gateway(lnk) {
window.open(SERVLET +
'?external_link=' + encodeURIComponent(lnk.href) +
'&external_target=' + encodeURIComponent(lnk.target) +
'&external_title=' + encodeURIComp...
java - Web Service using Axis 2: Complex type or simple type parameters?
The question is a specialization of:
OO style parameters vs type parameters
What if you want to define a Web Service operation? To have parameters beeing passed as complex types like this
public String insertPerson(Person person);
seems pretty cool since you're able to change th...
java - GWT: Capturing URL parameters in GET request
I need to build a GWT application that will be called by an external application with specific URL parameters.
For example:
http://www.somehost.com/com.app.client.Order.html?orderId=99999.
How do I capture the orderId parameter inside the GWT application?
Passing several parameters as a single parameter in Java
I've seen an example of it before, but I've never really found any good reference material dealing with it. I know it's possible to pass in several parameters, ints for example, by defining the method as
public void aMethod(int...a)
But I don't know any more about it than that. I've seen an example, and it returned the average of the ints passed.
Is this an out-dated way of passi...
Still can't find your answer? Check out these amazing Java communities for help...
Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)