Pongsakorn Semsuwan

Ranch Hand
+ Follow
since May 15, 2011
Pongsakorn likes ...
Eclipse IDE Java
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
3
Received in last 30 days
0
Total given
4
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Pongsakorn Semsuwan

We need your log to investigate the problem. The log will tell you which line it get Null Pointer Exception.

This Null Pointer Exception is occur when we try to access something in null object.
For example, myCar.turnRight() will cause a Nul Pointer Exception if myCar is null.

With this info, try to figure out why your object becomes null when you refresh the page.
10 years ago
First, use code tag when you include any code in your post.

I suggest you to alert your url before making a call so that you can know what you really call.
And then you might want to try calling getuser.jsp manually with emp_id passed
11 years ago
JSP
Have you try clearing cache in your browser and then call your second url so that we know it really is caching problem.
11 years ago
JSP
Keep your mid in your search form (the one with search button) using <input type="hidden" >
In your Demo.jsp, add a condition to see if request is come from Demo.jsp itself. (maybe check for the search button?). If request is not from search button, then do not connection to db. Instead, display a blank page with search form.

In Demo.jsp again, you have to set action of search form to itself. maybe <form action="" I'm not sure


By the way, MVC concept is highly recommended for web application development
Putting both logic, view , even connection to DB in jsp is quite unsophisticated.


11 years ago
JSP
In Servlet, get all the input parameters from your form and check if user put something in those optional fields or not.

If user does, you add an additional condition to your query. If not, go with you simplest mandatory query.
11 years ago
JSP
Servlet's doGet is actually means what you want it to do when user send a GET request, not to get data from it. The same applies to doPost.

To send data to JSP from Servlet, use


and then in your jsp,


I suggest you to read about MVC pattern for better understanding of good flow of web application.
11 years ago
AFAIK, of course it can be hosted in cloud. Cloud hosting service is not that different from normal web hosting service. It just have scalable resources when you need it and you pay for what you really use.

I don't have experience about cloud so I cannot suggest you a good read though.
11 years ago
Hi,

I'm just wondering whether to keep some of my variables in Constants class or keep it in web.xml

Say, I want to keep a variable of facebook graph api prefix or api_key, client_id

From my understand, the difference between Constants.java and web.xml is web.xml is easier to rewrite on compile using ant.
So you can replace your variables in web.xml according to what environment you are building you app for. (client_id varies by dev environment/prod environment, for example)

If I get it right, then facebook graph api prefix should be kept in Constants.java (because it always is "https://graph.facebook.com/" ) and api_key,client_id should be kept in web.xml ?


Please guide me what's the proper way to use them. Thank you.
11 years ago
Just did a quick search and found this
http://stackoverflow.com/questions/1102891/how-to-check-a-string-is-a-numeric-type-in-java
and
https://coderanch.com/t/401142/java/java/check-if-String-value-numeric

So basically, in your Servlet, you just get your checkNo variable from jsp and then call your method to validate it

11 years ago
JSP
This is how you set attribute to request and session. You have to set it before you forward your request to jsp.



Make sure that you understand the differences between session and request scope before choosing one.


And as R.Jain already mentioned, we need more information on what you are trying to do and how's your current situation.
11 years ago
Mine usually goes like this.

Servlet - get request and manipulate with input parameter
Service - apply your business logic
DAO - works with DB
Model - usually represent DB's table
FormBean - represent page

I open connection and commit transaction at service layer. Service layer will call DAO which is where you work with your DB (INSERT, UPDATE etc..).
I open connection and commit at service layer because some transaction might use more than one DAO.

For what you are searching for, one of my application store DBConnection in ThreadLocal
http://veerasundar.com/blog/2010/11/java-thread-local-how-to-use-and-code-sample/



Thank you Tim,

I read the document about this context thing and found this

http://tomcat.apache.org/tomcat-6.0-doc/config/context.html

Context elements may be explicitly defined:

- In the $CATALINA_BASE/conf/context.xml file: the Context element information will be loaded by all webapps.

- In the $CATALINA_BASE/conf/[enginename]/[hostname]/context.xml.default file: the Context element information will be loaded by all webapps of that host.

- In individual files (with a ".xml" extension) in the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory. The name of the file (less the .xml extension) will be used as the context path. Multi-level context paths may be defined using #, e.g. foo#bar.xml for a context path of /foo/bar. The default web application may be defined by using a file called ROOT.xml.

- Only if a context file does not exist for the application in the $CATALINA_BASE/conf/[enginename]/[hostname]/, in an individual file at /META-INF/context.xml inside the application files. If the web application is packaged as a WAR then /META-INF/context.xml will be copied to $CATALINA_BASE/conf/[enginename]/[hostname]/ and renamed to match the application's context path. Once this file exists, it will not be replaced if a new WAR with a newer /META-INF/context.xml is placed in the host's appBase.

- Inside a Host element in the main conf/server.xml.



Perhaps the context of my application is already defined in some of server configuration files and will not be rewrote even I specify it in META-INF/context.xml ?
11 years ago
Hi,

I'm new to Tomcat and wondering how to set each application context path without touching any file on server. (because I do not have an access to server. It's just a rent server)

I try googling and found article about putting context.xml in META-INF but it does not work.

Thank you in advance.
11 years ago
Hi,

This might be a silly question but I want to know that after I deployed wars/ears via admin console (standalone), where do those wars/ears go. Say, is there any directory to keep those files?

It is not the jboss-as-7.1.1.Final\standalone\deployments folder, right? because I don't see them there.


Thanks in advance.
11 years ago
This is how my web.xml looks like


MyServices

11 years ago